2009/11/10 Ted Kremenek <[email protected]>: > Hi Zhongxing, > > I think the previous wording was more in the right direction as it explained > the actual problem; "This can produce an unexpected result." is fairly > content-free unless you already know what the warning is about. > > How about: > > "Call to sizeof() returns the size of the pointer (X bytes) instead of how > much memory has been allocated by malloc()"
I think sizeof() never return the memory allocated by malloc(). (CWE is misleading) sizeof only returns the size of the object represented by the expression. > > (where X bytes is filled in with the pointer size) > > On Nov 8, 2009, at 6:28 PM, Zhongxing Xu wrote: > >> 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.}} >> +} >> >> >> _______________________________________________ >> cfe-commits mailing list >> [email protected] >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits > > _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
