Skip to content

Commit ad20169

Browse files
committed
Fix "pointer is null" static analyzer warnings. NFCI.
Use cast<> instead of dyn_cast<> and move into its users where its dereferenced immediately.
1 parent a888277 commit ad20169

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,12 +1006,9 @@ ProgramStateRef CStringChecker::InvalidateBuffer(CheckerContext &C,
10061006

10071007
bool CStringChecker::SummarizeRegion(raw_ostream &os, ASTContext &Ctx,
10081008
const MemRegion *MR) {
1009-
const TypedValueRegion *TVR = dyn_cast<TypedValueRegion>(MR);
1010-
10111009
switch (MR->getKind()) {
10121010
case MemRegion::FunctionCodeRegionKind: {
1013-
const NamedDecl *FD = cast<FunctionCodeRegion>(MR)->getDecl();
1014-
if (FD)
1011+
if (const auto *FD = cast<FunctionCodeRegion>(MR)->getDecl())
10151012
os << "the address of the function '" << *FD << '\'';
10161013
else
10171014
os << "the address of a function";
@@ -1025,16 +1022,20 @@ bool CStringChecker::SummarizeRegion(raw_ostream &os, ASTContext &Ctx,
10251022
return true;
10261023
case MemRegion::CXXThisRegionKind:
10271024
case MemRegion::CXXTempObjectRegionKind:
1028-
os << "a C++ temp object of type " << TVR->getValueType().getAsString();
1025+
os << "a C++ temp object of type "
1026+
<< cast<TypedValueRegion>(MR)->getValueType().getAsString();
10291027
return true;
10301028
case MemRegion::VarRegionKind:
1031-
os << "a variable of type" << TVR->getValueType().getAsString();
1029+
os << "a variable of type"
1030+
<< cast<TypedValueRegion>(MR)->getValueType().getAsString();
10321031
return true;
10331032
case MemRegion::FieldRegionKind:
1034-
os << "a field of type " << TVR->getValueType().getAsString();
1033+
os << "a field of type "
1034+
<< cast<TypedValueRegion>(MR)->getValueType().getAsString();
10351035
return true;
10361036
case MemRegion::ObjCIvarRegionKind:
1037-
os << "an instance variable of type " << TVR->getValueType().getAsString();
1037+
os << "an instance variable of type "
1038+
<< cast<TypedValueRegion>(MR)->getValueType().getAsString();
10381039
return true;
10391040
default:
10401041
return false;

0 commit comments

Comments
 (0)