[LLVMbugs] [Bug 22701] bogus "format string is not a string literal" warnings

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Feb 25 15:48:22 PST 2015


Richard Smith <richard-llvm at metafoo.co.uk> changed:

           What    |Removed                     |Added
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #5 from Richard Smith <richard-llvm at metafoo.co.uk> ---
That analysis is wrong.

> Looks like a clang bug because vprintf takes a format and an va_arg
> type which means there is no way to tell what the format is going to
> look into.

The warning is that a string of unknown origin is being used as a format
string. Warning about this doesn't require knowing what the arguments are.

> > remote.c:6986:37: warning: format string is not a string literal
> > [-Wformat-nonliteral]
> >   if (vsnprintf (rs->buf, max_size, format, ap) >= max_size)
> >                                     ^~~~~~
> > /usr/include/secure/_stdio.h:75:63: note: expanded from macro 'vsnprintf'
> >   __builtin___vsnprintf_chk (str, len, 0, __darwin_obsz(str), format, ap)
> See how they even warn about their own header too.

That warning is about a possible misuse of vsnprintf within remote.c. And
neither remote.c nor secure/_stdio.h is "[our] own header".

Consider a case like:

  va_list va;
  const char *p = gets(); // or read from network or whatever
  vprintf(p, va);

We do not need to know *anything* about the va_list to see that this is broken.
If you don't want us to check that you use format strings that can trivially be
shown to be "valid", then turn off -Wformat-nonliteral.

But in this case, the right thing to do is to annotate inferior_debug with
__attribute__((format(printf, 2, 3))).

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150225/a1dabe91/attachment.html>

More information about the llvm-bugs mailing list