@@ -1034,16 +1034,16 @@ void StreamChecker::preWrite(const FnDescription *Desc, const CallEvent &Call,
1034
1034
C.addTransition (State);
1035
1035
}
1036
1036
1037
- static std::optional< QualType> getPointeeType (const MemRegion *R) {
1037
+ static QualType getPointeeType (const MemRegion *R) {
1038
1038
if (!R)
1039
- return std::nullopt ;
1039
+ return {} ;
1040
1040
if (const auto *ER = dyn_cast<ElementRegion>(R))
1041
1041
return ER->getElementType ();
1042
1042
if (const auto *TR = dyn_cast<TypedValueRegion>(R))
1043
1043
return TR->getValueType ();
1044
1044
if (const auto *SR = dyn_cast<SymbolicRegion>(R))
1045
1045
return SR->getPointeeStaticType ();
1046
- return std::nullopt ;
1046
+ return {} ;
1047
1047
}
1048
1048
1049
1049
static std::optional<NonLoc> getStartIndex (SValBuilder &SVB,
@@ -1073,7 +1073,8 @@ tryToInvalidateFReadBufferByElements(ProgramStateRef State, CheckerContext &C,
1073
1073
const auto *Buffer =
1074
1074
dyn_cast_or_null<SubRegion>(Call.getArgSVal (0 ).getAsRegion ());
1075
1075
1076
- std::optional<QualType> ElemTy = getPointeeType (Buffer);
1076
+ const ASTContext &Ctx = C.getASTContext ();
1077
+ QualType ElemTy = getPointeeType (Buffer);
1077
1078
std::optional<SVal> StartElementIndex =
1078
1079
getStartIndex (C.getSValBuilder (), Buffer);
1079
1080
@@ -1086,18 +1087,20 @@ tryToInvalidateFReadBufferByElements(ProgramStateRef State, CheckerContext &C,
1086
1087
std::optional<int64_t > StartIndexVal =
1087
1088
getKnownValue (State, StartElementIndex.value_or (UnknownVal ()));
1088
1089
1089
- if (ElemTy && CountVal && Size && StartIndexVal) {
1090
+ if (! ElemTy. isNull () && CountVal && Size && StartIndexVal) {
1090
1091
int64_t NumBytesRead = Size .value () * CountVal.value ();
1091
- int64_t ElemSizeInChars =
1092
- C.getASTContext ().getTypeSizeInChars (*ElemTy).getQuantity ();
1092
+ int64_t ElemSizeInChars = Ctx.getTypeSizeInChars (ElemTy).getQuantity ();
1093
+ if (ElemSizeInChars == 0 )
1094
+ return nullptr ;
1095
+
1093
1096
bool IncompleteLastElement = (NumBytesRead % ElemSizeInChars) != 0 ;
1094
1097
int64_t NumCompleteOrIncompleteElementsRead =
1095
1098
NumBytesRead / ElemSizeInChars + IncompleteLastElement;
1096
1099
1097
1100
constexpr int MaxInvalidatedElementsLimit = 64 ;
1098
1101
if (NumCompleteOrIncompleteElementsRead <= MaxInvalidatedElementsLimit) {
1099
1102
return escapeByStartIndexAndCount (State, Call, C.blockCount (), Buffer,
1100
- * ElemTy, *StartIndexVal,
1103
+ ElemTy, *StartIndexVal,
1101
1104
NumCompleteOrIncompleteElementsRead);
1102
1105
}
1103
1106
}
0 commit comments