diff mbox series

trace-cmd: Quiet gcc warning of snprintf truncation

Message ID 20221109183204.33ae109d@rorschach.local.home (mailing list archive)
State Accepted
Commit 3913018ea01eedea0eb9d98c6321553317b5d54a
Headers show
Series trace-cmd: Quiet gcc warning of snprintf truncation | expand

Commit Message

Steven Rostedt Nov. 9, 2022, 11:32 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

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);

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 tracecmd/trace-setup-guest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tracecmd/trace-setup-guest.c b/tracecmd/trace-setup-guest.c
index 899848cb254a..6b0a9fe8a5bc 100644
--- a/tracecmd/trace-setup-guest.c
+++ b/tracecmd/trace-setup-guest.c
@@ -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");