[i-g-t,4/7] Fix truncate string in the snprintf
diff mbox

Message ID bc432c62f79076f1c1a757d8e41035ed1e7d3100.1531005542.git.rodrigosiqueiramelo@gmail.com
State New
Headers show

Commit Message

Rodrigo Siqueira July 7, 2018, 11:23 p.m. UTC
This patch fix the following GCC warning:

intel_reg.c: In function ‘dump_decode’:
warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=]
   snprintf(decode, sizeof(decode), "\n%s", bin);
intel_reg.c:203:3: note: ‘snprintf’ output between 2 and 1025 bytes into a destination of size 1024
[..]

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

Comments

Arkadiusz Hiler July 10, 2018, 2:07 p.m. UTC | #1
On Sat, Jul 07, 2018 at 08:23:17PM -0300, Rodrigo Siqueira wrote:
> This patch fix the following GCC warning:
> 
> intel_reg.c: In function ‘dump_decode’:
> warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=]
>    snprintf(decode, sizeof(decode), "\n%s", bin);
> intel_reg.c:203:3: note: ‘snprintf’ output between 2 and 1025 bytes into a destination of size 1024
> [..]

That's an odd error.

Line 203:
	snprintf(decode, sizeof(decode), "\n%s", bin);

man snprintf states:
	The functions snprintf() and vsnprintf() write at most size
	bytes (including the terminating null byte ('\0')) to str.

So this should be truncated correctly. Am I missing something?

I'll set up gcc 8.1 tomorrow and poke around.

> Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@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.18.0
>

Patch
diff mbox

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