Skip to content

Commit 37fde4b

Browse files
committed
[webkit.UncountedLambdaCapturesChecker] Fix a nullptr deference. (llvm#120702)
Added a nullptr check.
1 parent f55b40e commit 37fde4b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ class UncountedLambdaCapturesChecker
158158
if (!Init)
159159
return nullptr;
160160
TempExpr = dyn_cast<CXXBindTemporaryExpr>(Init->IgnoreParenCasts());
161+
if (!TempExpr)
162+
return nullptr;
161163
return dyn_cast_or_null<LambdaExpr>(TempExpr->getSubExpr());
162164
}
163165

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify %s
2+
// expected-no-diagnostics
3+
4+
struct Foo {
5+
int x;
6+
int y;
7+
Foo(int x, int y) : x(x) , y(y) { }
8+
~Foo() { }
9+
};
10+
11+
Foo bar(const Foo&);
12+
void foo() {
13+
int x = 7;
14+
int y = 5;
15+
bar(Foo(x, y));
16+
}

0 commit comments

Comments
 (0)