[PATCH] D140194: [clang-tidy] Fix crash in bugprone-suspicious-realloc-usage.
Balázs Kéri via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 21 00:30:21 PST 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG01303f6d1bba: [clang-tidy] Fix crash in bugprone-suspicious-realloc-usage. (authored by balazske).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140194/new/
https://reviews.llvm.org/D140194
Files:
clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
@@ -100,3 +100,10 @@
// 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]
+}
Index: clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
@@ -95,7 +95,7 @@
}
bool VisitStmt(const Stmt *S) {
for (const Stmt *Child : S->children())
- if (Visit(Child))
+ if (Child && Visit(Child))
return true;
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140194.484482.patch
Type: text/x-patch
Size: 1305 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221221/1f2ea324/attachment-0001.bin>
More information about the cfe-commits
mailing list