diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Analysis/CheckSizeofPointer.cpp | 2 | ||||
-rw-r--r-- | clang/test/Analysis/sizeofpointer.c | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/clang/lib/Analysis/CheckSizeofPointer.cpp b/clang/lib/Analysis/CheckSizeofPointer.cpp index c61f6f570ac..3cec5c9e98f 100644 --- a/clang/lib/Analysis/CheckSizeofPointer.cpp +++ b/clang/lib/Analysis/CheckSizeofPointer.cpp @@ -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/clang/test/Analysis/sizeofpointer.c b/clang/test/Analysis/sizeofpointer.c new file mode 100644 index 00000000000..e40c7185724 --- /dev/null +++ b/clang/test/Analysis/sizeofpointer.c @@ -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.}} +} |