[Intel-gfx] [PATCH i-g-t 4/7] Fix truncate string in the snprintf
Arkadiusz Hiler
arkadiusz.hiler at intel.com
Tue Jul 10 14:07:41 UTC 2018
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 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.18.0
>
More information about the Intel-gfx
mailing list