]> granicus.if.org Git - clang/commitdiff
Add a test case for CWE-467, and simplify the wording of the warning.
authorZhongxing Xu <xuzhongxing@gmail.com>
Mon, 9 Nov 2009 02:28:12 +0000 (02:28 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Mon, 9 Nov 2009 02:28:12 +0000 (02:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86504 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CheckSizeofPointer.cpp
test/Analysis/sizeofpointer.c [new file with mode: 0644]

index c61f6f570ac1d9206d8b38785e9a7f1f4374fad3..3cec5c9e98f51c0d383e3ae92051e5a215039d89 100644 (file)
@@ -47,7 +47,7 @@ void WalkAST::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
     SourceRange R = E->getArgumentExpr()->getSourceRange();
     BR.EmitBasicReport("Potential unintended use of sizeof() on pointer type",
                        "Logic",
-                       "The code calls sizeof() on a malloced pointer type, which always returns the wordsize/8. This can produce an unexpected result if the programmer intended to determine how much memory has been allocated.",
+                       "The code calls sizeof() on a pointer type. This can produce an unexpected result.",
                        E->getLocStart(), &R, 1);
   }
 }
diff --git a/test/Analysis/sizeofpointer.c b/test/Analysis/sizeofpointer.c
new file mode 100644 (file)
index 0000000..e40c718
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: clang-cc -analyze -warn-sizeof-pointer -verify %s
+
+struct s {
+};
+
+int f(struct s *p) {
+  return sizeof(p); // expected-warning{{The code calls sizeof() on a pointer type. This can produce an unexpected result.}}
+}