trace-cmd: Quiet gcc warning of snprintf truncation
PATCH 1/1 trace-cmd: Quiet gcc warning of snprintf truncation
From: "Steven Rostedt (Google)" <[email protected]>
Add 256 to the size of cmd[] and xml[] to quiet the warnings:
trace-setup-guest.c: In function ‘attach_guest_fifos’:
trace-setup-guest.c:247:1: warning: ‘%s’ directive output may be truncated writing up to 4095 bytes into a region of size 4058 [-Wformat-truncation=]
134 | snprintf(xml, sizeof(xml), xml_fmt, path, GUEST_PIPE_NAME, i);
| ~~~~
......
247 | }
| ^
trace-setup-guest.c:247:1: note: directive argument in the range [0, 2147483646]
trace-setup-guest.c:134:17: note: ‘snprintf’ output between 102 and 4206 bytes into a destination of size 4096
134 | snprintf(xml, sizeof(xml), xml_fmt, path, GUEST_PIPE_NAME, i);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~trace-setup-guest.c:247:1: warning: ‘%s’ directive output may be truncated writing up to 4095 bytes into a region of size 4063 [-Wformat-truncation=]
137 | snprintf(cmd, sizeof(cmd), cmd_fmt, guest, tmp_path);
| ~~~~~~~~
......
247 | }
| ^
trace-setup-guest.c:137:17: note: ‘snprintf’ output 58 or more bytes (assuming 4153) into a destination of size 4096
137 | snprintf(cmd, sizeof(cmd), cmd_fmt, guest, tmp_path);
--- tracecmd/trace-setup-guest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tracecmd/trace-setup-guest.c +1 -1
@@ -121,7 +121,7 @@ static int attach_guest_fifos(const char *guest, int nr_cpus)" <target type='virtio' name='%s%d'/>\n" "</channel>" ;char tmp_path[PATH_MAX ], path[PATH_MAX ]; -char cmd[PATH_MAX ], xml[PATH_MAX ]; +char cmd[PATH_MAX +256 ], xml[PATH_MAX +256 ];int i, fd, ret =0 ;strcpy (tmp_path,"/tmp/pipexmlXXXXXX" );
Signature · 1 line
2.35.1