[clang-tidy] As a simple heuristic don't emit a swap fixit that would create

negative-sized memsets.

memset(x, -1, 0) is still useless but swapping makes no sense here. Just emit
a warning.

llvm-svn: 213157
This commit is contained in:
Benjamin Kramer 2014-07-16 14:52:07 +00:00
parent d6a499077a
commit 806bcabcda
2 changed files with 6 additions and 1 deletions

View File

@ -63,7 +63,8 @@ void MemsetZeroLengthCheck::check(const MatchFinder::MatchResult &Result) {
return;
// If both arguments evaluate to zero emit a warning without fix suggestions.
if (Arg1->EvaluateAsInt(Value1, *Result.Context) && Value1 == 0) {
if (Arg1->EvaluateAsInt(Value1, *Result.Context) &&
(Value1 == 0 || Value1.isNegative())) {
diag(Call->getLocStart(), "memset of size zero");
return;
}

View File

@ -49,5 +49,9 @@ void foo(void *a, int xsize, int ysize) {
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero
// CHECK-FIXES: memset(a, v, 0);
memset(a, -1, v);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero
// CHECK-FIXES: memset(a, -1, v);
memtmpl<0>();
}