silence format truncation warning. 69/221769/1
authorSeunghun Lee <shiin.lee@samsung.com>
Tue, 7 Jan 2020 09:23:13 +0000 (18:23 +0900)
committerSeunghun Lee <shiin.lee@samsung.com>
Tue, 7 Jan 2020 09:40:03 +0000 (18:40 +0900)
add nul byte at the end of array to fix warning about possible
truncation by snprintf.

Change-Id: Ib399a9a2f2d552e427fa4c240a616e46267df584

src/tdm.c
src/tdm_layer.c

index c7289e8..76c1c5e 100644 (file)
--- a/src/tdm.c
+++ b/src/tdm.c
@@ -464,6 +464,7 @@ _tdm_display_update_caps_output(tdm_private_module *private_module, int pipe,
        char temp[TDM_NAME_LEN];
        tdm_error ret;
        double stamp;
+       int n;
 
        stamp = tdm_helper_get_time();
        ret = func_output->output_get_capability(output_backend, caps);
@@ -476,7 +477,11 @@ _tdm_display_update_caps_output(tdm_private_module *private_module, int pipe,
        }
 
        /* FIXME: Use model for tdm client to distinguish amoung outputs */
-       snprintf(temp, TDM_NAME_LEN, "%s-%d", caps->model, pipe);
+       n = snprintf(temp, sizeof(temp), "%s-%d", caps->model, pipe);
+       if ((size_t)n >= sizeof(temp)) {
+                temp[sizeof(temp) - 1] = '\0';
+       }
+
        snprintf(caps->model, TDM_NAME_LEN, "%s", temp);
 
        return TDM_ERROR_NONE;
index 22cdb47..488f498 100644 (file)
@@ -343,6 +343,7 @@ _tdm_layer_dump_buffer(tdm_layer *layer, tbm_surface_h buffer)
        tdm_private_layer *l = NULL;
        char *p = bufs;
        int *remain = &len;
+       int n;
 
        pipe = private_output->pipe;
        zpos = private_layer->caps.zpos;
@@ -354,7 +355,10 @@ _tdm_layer_dump_buffer(tdm_layer *layer, tbm_surface_h buffer)
                TDM_SNPRINTF(p, remain, "_%p", l->showing_buffer->buffer);
        }
 
-       snprintf(fname, sizeof(fname), "tdm_%d_lyr_%d%s", pipe, zpos, bufs);
+       n = snprintf(fname, sizeof(fname), "tdm_%d_lyr_%d%s", pipe, zpos, bufs);
+       if ((size_t)n >= sizeof(fname)) {
+               fname[sizeof(fname) - 1] = '\0';
+       }
 
        tbm_surface_internal_dump_buffer(buffer, fname);
        TDM_DBG("%s dump excute", fname);