Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 79bf64dc authored by Raja M's avatar Raja M
Browse files

GCC compiler warning fix for sprintf into snprintf

To fix GCC WARNINGS while building.
or
To support error free -D_FORTIFY_SOURCE=2 strict mode compilation.
parent a2f37e4f
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -54,14 +54,14 @@ static int check_response(Transport* transport, uint32_t size, char* response) {
    while (true) {
        int r = transport->Read(status, 64);
        if (r < 0) {
            sprintf(ERROR, "status read failed (%s)", strerror(errno));
            snprintf(ERROR, sizeof(ERROR), "status read failed (%s)", strerror(errno));
            transport->Close();
            return -1;
        }
        status[r] = 0;

        if (r < 4) {
            sprintf(ERROR, "status malformed (%d bytes)", r);
            snprintf(ERROR, sizeof(ERROR), "status malformed (%d bytes)", r);
            transport->Close();
            return -1;
        }
@@ -80,7 +80,7 @@ static int check_response(Transport* transport, uint32_t size, char* response) {

        if (!memcmp(status, "FAIL", 4)) {
            if (r > 4) {
                sprintf(ERROR, "remote: %s", status + 4);
                snprintf(ERROR, sizeof(ERROR), "remote: %s", status + 4);
            } else {
                strcpy(ERROR, "remote failure");
            }
@@ -108,7 +108,7 @@ static int check_response(Transport* transport, uint32_t size, char* response) {
static int _command_start(Transport* transport, const char* cmd, uint32_t size, char* response) {
    size_t cmdsize = strlen(cmd);
    if (cmdsize > 64) {
        sprintf(ERROR, "command too large");
        snprintf(ERROR, sizeof(ERROR), "command too large");
        return -1;
    }

@@ -117,7 +117,7 @@ static int _command_start(Transport* transport, const char* cmd, uint32_t size,
    }

    if (transport->Write(cmd, cmdsize) != static_cast<int>(cmdsize)) {
        sprintf(ERROR, "command write failed (%s)", strerror(errno));
        snprintf(ERROR, sizeof(ERROR), "command write failed (%s)", strerror(errno));
        transport->Close();
        return -1;
    }
@@ -128,12 +128,12 @@ static int _command_start(Transport* transport, const char* cmd, uint32_t size,
static int _command_data(Transport* transport, const void* data, uint32_t size) {
    int r = transport->Write(data, size);
    if (r < 0) {
        sprintf(ERROR, "data transfer failure (%s)", strerror(errno));
        snprintf(ERROR, sizeof(ERROR), "data transfer failure (%s)", strerror(errno));
        transport->Close();
        return -1;
    }
    if (r != ((int) size)) {
        sprintf(ERROR, "data transfer failure (short transfer)");
        snprintf(ERROR, sizeof(ERROR), "data transfer failure (short transfer)");
        transport->Close();
        return -1;
    }
@@ -182,7 +182,7 @@ int fb_command_response(Transport* transport, const char* cmd, char* response) {

int fb_download_data(Transport* transport, const void* data, uint32_t size) {
    char cmd[64];
    sprintf(cmd, "download:%08x", size);
    snprintf(cmd, sizeof(cmd), "download:%08x", size);
    return _command_send(transport, cmd, data, size, 0) < 0 ? -1 : 0;
}

@@ -216,7 +216,7 @@ static int fb_download_data_sparse_write(void *priv, const void *data, int len)

    if (len > TRANSPORT_BUF_SIZE) {
        if (transport_buf_len > 0) {
            sprintf(ERROR, "internal error: transport_buf not empty\n");
            snprintf(ERROR, sizeof(ERROR), "internal error: transport_buf not empty\n");
            return -1;
        }
        to_write = round_down(len, TRANSPORT_BUF_SIZE);
@@ -230,7 +230,7 @@ static int fb_download_data_sparse_write(void *priv, const void *data, int len)

    if (len > 0) {
        if (len > TRANSPORT_BUF_SIZE) {
            sprintf(ERROR, "internal error: too much left for transport_buf\n");
            snprintf(ERROR, sizeof(ERROR), "internal error: too much left for transport_buf\n");
            return -1;
        }
        memcpy(transport_buf, ptr, len);
@@ -257,7 +257,7 @@ int fb_download_data_sparse(Transport* transport, struct sparse_file* s) {
    }

    char cmd[64];
    sprintf(cmd, "download:%08x", size);
    snprintf(cmd, sizeof(cmd), "download:%08x", size);
    int r = _command_start(transport, cmd, size, 0);
    if (r < 0) {
        return -1;