[Bug middle-end/85139] [8 Regression] Spurious format truncation warning

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Apr 3 14:48:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85139

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
To avoid the warning, cast the argument of the %04X directive to unsigned
short:

  snprintf(s, sizeof(s), "usb:v%04Xp%04X*", (unsigned short)vn, (unsigned
short)pn);

(Note that even though casting an int to signed short will most likely work, it
isn't strictly correct.)


More information about the Gcc-bugs mailing list