Skip to content

Commit

Permalink
[clang-tidy] Fix crash in bugprone-suspicious-realloc-usage.
Browse files Browse the repository at this point in the history
The problem occurs if a statement is found by the checker that has a null child.
Fixes issue #59518.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D140194
  • Loading branch information
balazske committed Dec 21, 2022
1 parent 3f811b2 commit 01303f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Expand Up @@ -95,7 +95,7 @@ class FindAssignToVarBefore
}
bool VisitStmt(const Stmt *S) {
for (const Stmt *Child : S->children())
if (Visit(Child))
if (Child && Visit(Child))
return true;
return false;
}
Expand Down
Expand Up @@ -100,3 +100,10 @@ void warn_if_copy_exists_after(void *p) {
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
void *q = p;
}

void test_null_child(void *p) {
for (;;)
break;
p = realloc(p, 111);
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
}

0 comments on commit 01303f6

Please sign in to comment.