[cfe-commits] r86504 - in /cfe/trunk: lib/Analysis/CheckSizeofPointer.cpp test/Analysis/sizeofpointer.c
Zhongxing Xu
xuzhongxing at gmail.com
Sun Nov 8 18:28:12 PST 2009
Author: zhongxingxu
Date: Sun Nov 8 20:28:12 2009
New Revision: 86504
URL: http://llvm.org/viewvc/llvm-project?rev=86504&view=rev
Log:
Add a test case for CWE-467, and simplify the wording of the warning.
Added:
cfe/trunk/test/Analysis/sizeofpointer.c
Modified:
cfe/trunk/lib/Analysis/CheckSizeofPointer.cpp
Modified: cfe/trunk/lib/Analysis/CheckSizeofPointer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckSizeofPointer.cpp?rev=86504&r1=86503&r2=86504&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CheckSizeofPointer.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckSizeofPointer.cpp Sun Nov 8 20:28:12 2009
@@ -47,7 +47,7 @@
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);
}
}
Added: cfe/trunk/test/Analysis/sizeofpointer.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/sizeofpointer.c?rev=86504&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/sizeofpointer.c (added)
+++ cfe/trunk/test/Analysis/sizeofpointer.c Sun Nov 8 20:28:12 2009
@@ -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.}}
+}
More information about the cfe-commits
mailing list