On Tue, Jul 7, 2020 at 5:08 PM <[email protected]> wrote:
>
>  Which method to get rid of this error message do you prefer:
> ...
> src/jtag/drivers/arm-jtag-ew.c: In function ?armjtagew_debug_buffer?:
> src/jtag/drivers/arm-jtag-ew.c:789:22: error: ?%04x? directive output may be 
> truncated writing between 4 and 8 bytes into a region of size 5 
> [-Werror=format-truncation=]
>    snprintf(line, 5, "%04x", i);
>                       ^~~~
> src/jtag/drivers/arm-jtag-ew.c:789:21: note: directive argument in the range 
> [0, 2147483632]
>    snprintf(line, 5, "%04x", i);
>                      ^~~~~~
> ...
>
> and similarily for src/jtag/drivers/opendous.c.
>
> ///
>  The code is last in file:
>
> #ifdef _DEBUG_USB_COMMS_
> #define BYTES_PER_LINE  16
>
> static void armjtagew_debug_buffer(uint8_t *buffer, int length)
> {
>         char line[81];
>         char s[4];
>         int i;
>         int j;
>
>         for (i = 0; i < length; i += BYTES_PER_LINE) {
>                 snprintf(line, 5, "%04x", i);
>                 for (j = i; j < i + BYTES_PER_LINE && j < length; j++) {
>                         snprintf(s, 4, " %02x", buffer[j]);
>                         strcat(line, s);
>                 }
>                 LOG_DEBUG("%s", line);
>
>                 /* Prevent GDB timeout (writing to log might take some time) 
> */
>                 keep_alive();
>         }
> }
> #endif
>
> and is about what to print for the byte offset index first on output
> line.
>
> As a quick fix to make it compile I just added a (uint16_t) cast before
> i in the snprintf-line, but one could change i, j and length to uint16_t
> and use SCNx16 from inttypes.h, or change the #define and snprintf to
> accept the full range of int values.
>

Hi Karl,

with my gcc 10.1.0 seams enough to change
- the types of "i" and "j" in the function and
- of "length" in the function prototype
all to "unsigned int".
It seems a good compromise to avoid cast and keep code readability.

Would you check if it works on your side too?
Could you propose a patch in gerrit for further check?

Thanks
Antonio

> Regards,
> /Karl Hammar


_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to