@@ -, +, @@ Hex objects PR binutils/18750 * ihex.c (ihex_bad_byte): Increase the size of buf to allow for all possible 32 bit unsigned int values, use snprintf() to future proof the conversion operation, and properly check the return value of snprintf(). --- bfd/ihex.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/bfd/ihex.c +++ a/bfd/ihex.c @@ -216,10 +216,17 @@ ihex_bad_byte (bfd *abfd, unsigned int lineno, int c, bfd_boolean error) } else { - char buf[10]; + char buf[1 + 11 + 1]; /* '\\' + "37777777777" + '\0' */ if (! ISPRINT (c)) - sprintf (buf, "\\%03o", (unsigned int) c); + { + int len = snprintf (buf, sizeof(buf), "\\%03o", (unsigned int) c); + + if (len < 0 || (unsigned int) len >= sizeof(buf)) { + buf[0] = '?'; + buf[1] = '\0'; + } + } else { buf[0] = c; --