[PATCH] trace-cmd: Quiet gcc warning of snprintf truncation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx>

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@xxxxxxxxxxx>
---
 tracecmd/trace-setup-guest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux