forked from OSchip/llvm-project
[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:
parent
d6a499077a
commit
806bcabcda
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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>();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue