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

--- Comment #4 from Martin Husemann <martin at netbsd dot org> ---
This is scary.

So in the future there will be valid reasons for the truncation warning, but
you are not offering any way to suppress the totally useless false positives?

My problem with this warning is that (as of gcc 7.4) it has a S/N ratio very
close to 0. snprintf will truncate the output? Yes, that is what the standard
says and what I expect from it.

There is no usefull more targeted workaround than turning it off.

I actually did sucessfully quell the warning with this idiom:

  char buf[STRLEN];
  int r = snprintf(buf, sizeof(buf), format, ....);
  if (r >= sizeof(buf))
    buf[sizeof(buf)-1] = 0;

but that is of course totally stupid (and hopefully gcc will eliminate the if
() part completely (but since the warning goes away, it seems not to do that).

We always compile all stuff with -Wall and -Werror, we even dealt with the very
painfull (and much too simplistic) case fallthrough checker. But with the
format truncation there is no option but to either make the code worse or turn
it off completely.

Reply via email to