[igt-dev] [PATCH v2 i-g-t 2/2] Fix truncate string in the snprintf

Rodrigo Siqueira rodrigosiqueiramelo at gmail.com
Sun Jul 29 12:41:45 UTC 2018


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 at gmail.com>
---
 tools/intel_reg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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];
 
-- 
2.17.0



More information about the igt-dev mailing list