[cfe-commits] r150260 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/format-strings.cpp
David Blaikie
dblaikie at gmail.com
Fri Feb 10 11:42:27 PST 2012
On Fri, Feb 10, 2012 at 11:13 AM, Ted Kremenek <kremenek at apple.com> wrote:
> Author: kremenek
> Date: Fri Feb 10 13:13:51 2012
> New Revision: 150260
>
> URL: http://llvm.org/viewvc/llvm-project?rev=150260&view=rev
> Log:
> Enhance checking for null format string literal to take into account __null. Fixes <rdar://problem/8269537>.
>
> Modified:
> cfe/trunk/lib/Sema/SemaChecking.cpp
> cfe/trunk/test/SemaCXX/format-strings.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=150260&r1=150259&r2=150260&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Feb 10 13:13:51 2012
> @@ -1381,6 +1381,7 @@
> inFunctionCall);
> }
>
> + case Stmt::GNUNullExprClass:
> case Stmt::IntegerLiteralClass:
could/should this be generalized over all null pointer literals?
This, for example, still flags 'nullptr' and (to a more questionable
extent) 'false' which is still technically a valid null pointer. If
I'm reading/testing it correctly, that is.
> // Technically -Wformat-nonliteral does not warn about this case.
> // The behavior of printf and friends in this case is implementation
>
> Modified: cfe/trunk/test/SemaCXX/format-strings.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/format-strings.cpp?rev=150260&r1=150259&r2=150260&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/format-strings.cpp (original)
> +++ cfe/trunk/test/SemaCXX/format-strings.cpp Fri Feb 10 13:13:51 2012
> @@ -39,3 +39,14 @@
> printf(foo.gettext("%d"), i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}}
> printf(Foo::gettext_static("%d"), i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}}
> }
> +
> +// Test handling __null for format string literal checking.
> +extern "C" {
> + int test_null_format(const char *format, ...) __attribute__((__format__ (__printf__, 1, 2)));
> +}
> +
> +void rdar8269537(const char *f)
> +{
> + test_null_format(__null); // no-warning
> + test_null_format(f); // expected-warning {{not a string literal}}
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list