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

--- Comment #9 from Mark Wielaard <mark at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #8)
> The patch I posted for the related pr88993 also relaxes this warning for
> printf and fprintf:  https://gcc.gnu.org/ml/gcc-patches/2019-02/msg00224.html
> 
> Like in the case of pr88993, the warning is by design and (in my view) makes
> sense for sprintf but it's not very useful for the other functions where
> very little code worries about exceeding these limits (or even cares about
> the functions failing as they can for many other reasons).

I tried that patch, but it does not fix this issue. This case now triggers the
following warning, which isn't guarded by is_string_func:

      /* The directive output or either causes or may cause the total
         length of output to exceed INT_MAX bytes.  */

      if (likelyximax && fmtres.range.min == fmtres.range.max)
        warned = fmtwarn (dirloc, argloc, NULL, info.warnopt (),
                          "%<%.*s%> directive output of %wu bytes causes "
                          "result to exceed %<INT_MAX%>", dirlen,
                          target_to_host (hostdir, sizeof hostdir, dir.beg),
                          fmtres.range.min);

So with that patch we get:

/home/mark/src/elfutils/src/readelf.c: In function ‘print_debug_str_section’:
/home/mark/src/elfutils/src/readelf.c:10167:15: error: ‘]  "’ directive output
of 4 bytes causes result to exceed ‘INT_MAX’ [-Werror=format-overflow=]
10167 |       printf (" [%*" PRIx64 "]  \"%s\"\n", digits, (uint64_t) offset,
str);
      |               ^~~~~~
/home/mark/src/elfutils/src/readelf.c:10167:30: note: format string is defined
here
10167 |       printf (" [%*" PRIx64 "]  \"%s\"\n", digits, (uint64_t) offset,
str);
      |                              ^~~~~
cc1: all warnings being treated as errors

Which is actually more mysterious than the previous warning (without the patch
as shown in description).

Reply via email to