Skip to content

Commit 4a5df73

Browse files
committed
[analyzer] PR43551: Do not dereferce void* in UndefOrNullArgVisitor.
Patch by Kristóf Umann! Differential Revision: https://reviews.llvm.org/D68591 llvm-svn: 375329
1 parent ab2cec8 commit 4a5df73

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,8 +2034,6 @@ bool bugreporter::trackExpressionValue(const ExplodedNode *InputNode,
20342034

20352035
// Is it a symbolic value?
20362036
if (auto L = V.getAs<loc::MemRegionVal>()) {
2037-
report.addVisitor(std::make_unique<UndefOrNullArgVisitor>(L->getRegion()));
2038-
20392037
// FIXME: this is a hack for fixing a later crash when attempting to
20402038
// dereference a void* pointer.
20412039
// We should not try to dereference pointers at all when we don't care
@@ -2056,10 +2054,14 @@ bool bugreporter::trackExpressionValue(const ExplodedNode *InputNode,
20562054
else if (CanDereference)
20572055
RVal = LVState->getSVal(L->getRegion());
20582056

2059-
if (CanDereference)
2057+
if (CanDereference) {
2058+
report.addVisitor(
2059+
std::make_unique<UndefOrNullArgVisitor>(L->getRegion()));
2060+
20602061
if (auto KV = RVal.getAs<KnownSVal>())
20612062
report.addVisitor(std::make_unique<FindLastStoreBRVisitor>(
20622063
*KV, L->getRegion(), EnableNullFPSuppression, TKind, SFC));
2064+
}
20632065

20642066
const MemRegion *RegionRVal = RVal.getAsRegion();
20652067
if (RegionRVal && isa<SymbolicRegion>(RegionRVal)) {

clang/test/Analysis/novoidtypecrash.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
// RUN: %clang_analyze_cc1 -analyzer-checker=core %s
2+
x;
3+
y(void **z) { // no-crash
4+
*z = x;
5+
int *w;
6+
y(&w);
7+
*w;
8+
}
9+
210
a;
3-
b(void **c) { // no-crash
4-
*c = a;
5-
int *d;
6-
b(&d);
7-
*d;
11+
b(*c) {}
12+
e(*c) {
13+
void *d = f();
14+
b(d);
15+
*c = d;
16+
}
17+
void *g() {
18+
e(&a);
19+
return a;
20+
}
21+
j() {
22+
int h;
23+
char i = g();
24+
if (i)
25+
for (; h;)
26+
;
827
}

0 commit comments

Comments
 (0)