diff options
author | Philip Withnall <philip.withnall@collabora.co.uk> | 2014-05-06 14:56:39 +0100 |
---|---|---|
committer | Philip Withnall <philip.withnall@collabora.co.uk> | 2014-05-06 14:56:39 +0100 |
commit | 72fe9085710e7170e88249a112e201fafe37f080 (patch) | |
tree | 2b1149d0e5ae44eaeab1e3e545b53d04d25e0e5a | |
parent | 6977a14d9d9f074d0196b8abd2fa60388a40a87f (diff) |
clang-plugin: Don’t confuse integer constants with NULL
The integer constant 0 can be interpreted as NULL, so only perform NULL
pointer checks when the expected type is a pointer.
-rw-r--r-- | clang-plugin/gvariant-checker.cpp | 3 | ||||
-rw-r--r-- | tests/gvariant-new.c | 8 |
2 files changed, 10 insertions, 1 deletions
diff --git a/clang-plugin/gvariant-checker.cpp b/clang-plugin/gvariant-checker.cpp index ba23f00..80eeb6a 100644 --- a/clang-plugin/gvariant-checker.cpp +++ b/clang-plugin/gvariant-checker.cpp @@ -303,7 +303,8 @@ _consume_variadic_argument (QualType expected_type, bool is_null_constant = arg->isNullPointerConstant (context, Expr::NPC_ValueDependentIsNull); - if (is_null_constant && !(flags & CHECK_FLAG_ALLOW_MAYBE)) { + if (is_null_constant && !(flags & CHECK_FLAG_ALLOW_MAYBE) && + expected_type->isPointerType ()) { gchar *error; error = g_strdup_printf ( diff --git a/tests/gvariant-new.c b/tests/gvariant-new.c index 45f1f13..6a787b2 100644 --- a/tests/gvariant-new.c +++ b/tests/gvariant-new.c @@ -177,6 +177,14 @@ } /* + * No error + */ +{ + // This could be interpreted as a NULL pointer constant. + floating_variant = g_variant_new ("u", 0); +} + +/* * Expected a GVariant variadic argument of type ‘long’ but saw one of type ‘char *’. * floating_variant = g_variant_new ("x", "nope"); * ^ |