diff mbox series

[v2,i-g-t,2/2] Fix truncate string in the snprintf

Message ID a97efb595d6393d610ad6e4f9580fe66488835e2.1532867044.git.rodrigosiqueiramelo@gmail.com (mailing list archive)
State New, archived
Headers show
Series Fix some GCC warnings | expand

Commit Message

Rodrigo Siqueira July 29, 2018, 12:41 p.m. UTC
This patch fix the following GCC warning:

../tools/intel_reg.c: In function ‘dump_decode’:
../tools/intel_reg.c:203:41: warning: ‘snprintf’ output may be truncated
before the last format character [-Wformat-truncation=]
   snprintf(decode, sizeof(decode), "\n%s", bin);
[..]
../tools/intel_reg.c:200:40: warning: ‘%s’ directive output may be
truncated writing up to 1023 bytes into a region of size 1022
[-Wformat-truncation=]
    snprintf(decode, sizeof(decode), " (%s)\n%s", tmp, bin);
[..]
../tools/intel_reg.c:200:4: note: ‘snprintf’ output between 5 and 2051
bytes into a destination of size 1024
    snprintf(decode, sizeof(decode), " (%s)\n%s", tmp, bin);
[..]

Notice that snprintf writes in the decode variable the values from tmp
and bin. These two variables together have 2048 bytes and some extra
characters added by snprintf, this commit changed the size of decode to
support the combination.

Changes since V1:
 - Improve commit message

Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
---
 tools/intel_reg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tools/intel_reg.c b/tools/intel_reg.c
index ddff2794..15ebb86a 100644
--- a/tools/intel_reg.c
+++ b/tools/intel_reg.c
@@ -180,7 +180,7 @@  static void to_binary(char *buf, size_t buflen, uint32_t val)
 
 static void dump_decode(struct config *config, struct reg *reg, uint32_t val)
 {
-	char decode[1024];
+	char decode[2060];
 	char tmp[1024];
 	char bin[1024];