summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/warn-memset-bad-sizeof.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Reapply [Sema] Add sizeof diagnostics for bzeroBruno Cardoso Lopes2016-08-101-0/+43
| | | | | | | | | | | | | | | | | | | | | | | | | Reapply r277787. For memset (and others) we can get diagnostics like: struct stat { int x; }; void foo(struct stat *stamps) { bzero(stamps, sizeof(stamps)); memset(stamps, 0, sizeof(stamps)); } t.c:7:28: warning: 'memset' call operates on objects of type 'struct stat' while the size is based on a different type 'struct stat *' [-Wsizeof-pointer-memaccess] memset(stamps, 0, sizeof(stamps)); ~~~~~~ ^~~~~~ t.c:7:28: note: did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)? memset(stamps, 0, sizeof(stamps)); ^~~~~~ This patch implements the same class of warnings for bzero. Differential Revision: https://reviews.llvm.org/D22525 rdar://problem/18963514 llvm-svn: 278264
* Revert "[Sema] Add sizeof diagnostics for bzero"Bruno Cardoso Lopes2016-08-051-43/+0
| | | | | | This reverts commit r277787, which caused PR28870. llvm-svn: 277830
* [Sema] Add sizeof diagnostics for bzeroBruno Cardoso Lopes2016-08-041-0/+43
| | | | | | | | | | | | | | | | | | | | | | | | | For memset (and others) we can get diagnostics like: struct stat { int x; }; void foo(struct stat *stamps) { bzero(stamps, sizeof(stamps)); memset(stamps, 0, sizeof(stamps)); } t.c:7:28: warning: 'memset' call operates on objects of type 'struct stat' while the size is based on a different type 'struct stat *' [-Wsizeof-pointer-memaccess] memset(stamps, 0, sizeof(stamps)); ~~~~~~ ^~~~~~ t.c:7:28: note: did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)? memset(stamps, 0, sizeof(stamps)); ^~~~~~ This patch implements the same class of warnings for bzero. Differential Revision: https://reviews.llvm.org/D22525 rdar://problem/18963514 llvm-svn: 277787
* -Wdynamic-class-memaccess: Also warn about array types.Nico Weber2015-03-211-0/+2
| | | | | | | It looks like not warning on this was an oversight in the original implementation of this warning. llvm-svn: 232900
* Change wording of 'memcpy' type mismatch warning and remove fixit.Anna Zaks2012-05-301-12/+12
| | | | | | As per comments following r157659. llvm-svn: 157722
* StmtProfiler: Add a null check for child statements.Peter Collingbourne2012-03-011-0/+8
| | | | llvm-svn: 151812
* Add a new compiler warning, which flags anti-patterns used as the sizeAnna Zaks2012-02-011-2/+0
| | | | | | | | | | | argument in strncat. The warning is ignored by default since it needs more qualification. TODO: The warning message and the note are messy when strncat is a builtin due to the macro expansion. llvm-svn: 149524
* Extend -Wno-sizeof-array-argument to strncpy and friends.Nico Weber2011-10-131-0/+25
| | | | | | This finds 2 bugs in chromium and 1 in hunspell, with 0 false positives. llvm-svn: 141902
* Extend memset/memcpy/memmove checking to include memcmpMatt Beaumont-Gay2011-08-051-0/+13
| | | | llvm-svn: 136950
* Rework the warning for 'memset(p, 0, sizeof(p))' where 'p' is a pointerChandler Carruth2011-06-161-7/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | and the programmer intended to write 'sizeof(*p)'. There are several elements to the new version: 1) The actual expressions are compared in order to more accurately flag the case where the pattern that works for an array has been used, or a '*' has been omitted. 2) Only do a loose type-based check for record types. This prevents us from warning when we happen to be copying around chunks of data the size of a pointer and the pointer types for the sizeof and source/dest match. 3) Move all the diagnostics behind the runtime diagnostic filter. Not sure this is really important for this particular diagnostic, but almost everything else in SemaChecking.cpp does so. 4) Make the wording of the diagnostic more precise and informative. At least to my eyes. 5) Provide highlighting for the two expressions which had the unexpected similarity. 6) Place this diagnostic under a flag: -Wsizeof-pointer-memaccess This uses the Stmt::Profile system for computing #1. Because of the potential cost, this is guarded by the warning flag. I'd be interested in feedback on how bad this is in practice; I would expect it to be quite cheap in practice. Ideas for a cheaper / better way to do this are also welcome. The diagnostic wording could likely use some further wordsmithing. Suggestions welcome here. The goals I had were to: clarify that its the interaction of 'memset' and 'sizeof' and give more reasonable suggestions for a resolution. An open question is whether these diagnostics should have the note attached for silencing by casting the dest/source pointer to void*. llvm-svn: 133155
* Fix my test case from r133136 so that it actually represents the codeChandler Carruth2011-06-161-4/+4
| | | | | | pattern found in the wild where this warning was firing. llvm-svn: 133143
* Skip both character pointers and void pointers when diagnosing badChandler Carruth2011-06-161-3/+4
| | | | | | | | | | | | | argument types for mem{set,cpy,move}. Character pointers, much like void pointers, often point to generic "memory", so trying to check whether they match the type of the argument to 'sizeof' (or other checks) is unproductive and often results in false positives. Nico, please review; does this miss any of the bugs you were trying to find with this warning? The array test case you had should be caught by the array-specific sizeof warning I think. llvm-svn: 133136
* Build fix attempt.Nico Weber2011-06-151-1/+1
| | | | llvm-svn: 133039
* Warn on memset(ptr, 0, sizeof(ptr)). Diagnostic wording by Jordy Rose.Nico Weber2011-06-141-0/+97
llvm-svn: 132996
OpenPOWER on IntegriCloud