[cfe-dev] warning for passing NULL as format arg

Erik Pilkington via cfe-dev cfe-dev at lists.llvm.org
Mon Apr 8 16:53:57 PDT 2019


Hi Matt,

Emitting something like -Wnonnull on builtins that require non-null 
arguments seems totally reasonable to me, there are probably other 
builtins where this is a more plausible mistake to make. If you're 
interested in implementing this, there are some similar diagnostics in 
SemaChecking.cpp, which would be a good starting point.

Erik

On 4/6/19 1:57 PM, Matthew Fernandez via cfe-dev wrote:
> Hello cfe-dev,
>
> I came across some surprising behavior involving -Wformat. I was generating some C code and an error in the code generator led to it emitting something similar to the following:
>
>      printf(NULL, “foo”);
>
> Using Clang on macOS (version “Apple LLVM version 10.0.0 (clang-1000.11.45.5)”) this compiles warning-free even with -Wformat -Wformat-nonliteral -Wformat-zero-length. Is this to be expected? Obviously it’s quite unlikely a human would write this code, but I was surprised the compiler had nothing to say about this.
>
> Thanks,
> Matt
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list