@@ -615,30 +615,22 @@ class StreamChecker : public Checker<check::PreCall, eval::Call,
615
615
});
616
616
}
617
617
618
- void initMacroValues (CheckerContext &C ) const {
618
+ void initMacroValues (const Preprocessor &PP ) const {
619
619
if (EofVal)
620
620
return ;
621
621
622
- if (const std::optional<int > OptInt =
623
- tryExpandAsInteger (" EOF" , C.getPreprocessor ()))
622
+ if (const std::optional<int > OptInt = tryExpandAsInteger (" EOF" , PP))
624
623
EofVal = *OptInt;
625
624
else
626
625
EofVal = -1 ;
627
- if (const std::optional<int > OptInt =
628
- tryExpandAsInteger (" SEEK_SET" , C.getPreprocessor ()))
626
+ if (const std::optional<int > OptInt = tryExpandAsInteger (" SEEK_SET" , PP))
629
627
SeekSetVal = *OptInt;
630
- if (const std::optional<int > OptInt =
631
- tryExpandAsInteger (" SEEK_END" , C.getPreprocessor ()))
628
+ if (const std::optional<int > OptInt = tryExpandAsInteger (" SEEK_END" , PP))
632
629
SeekEndVal = *OptInt;
633
- if (const std::optional<int > OptInt =
634
- tryExpandAsInteger (" SEEK_CUR" , C.getPreprocessor ()))
630
+ if (const std::optional<int > OptInt = tryExpandAsInteger (" SEEK_CUR" , PP))
635
631
SeekCurVal = *OptInt;
636
632
}
637
633
638
- void initVaListType (CheckerContext &C) const {
639
- VaListType = C.getASTContext ().getBuiltinVaListType ().getCanonicalType ();
640
- }
641
-
642
634
// / Searches for the ExplodedNode where the file descriptor was acquired for
643
635
// / StreamSym.
644
636
static const ExplodedNode *getAcquisitionSite (const ExplodedNode *N,
@@ -880,9 +872,6 @@ static ProgramStateRef escapeArgs(ProgramStateRef State, CheckerContext &C,
880
872
881
873
void StreamChecker::checkPreCall (const CallEvent &Call,
882
874
CheckerContext &C) const {
883
- initMacroValues (C);
884
- initVaListType (C);
885
-
886
875
const FnDescription *Desc = lookupFn (Call);
887
876
if (!Desc || !Desc->PreFn )
888
877
return ;
@@ -938,7 +927,6 @@ void StreamChecker::evalFopen(const FnDescription *Desc, const CallEvent &Call,
938
927
assert (RetSym && " RetVal must be a symbol here." );
939
928
940
929
State = State->BindExpr (CE, C.getLocationContext (), RetVal);
941
- State = assumeNoAliasingWithStdStreams (State, RetVal, C);
942
930
943
931
// Bifurcate the state into two: one with a valid FILE* pointer, the other
944
932
// with a NULL.
@@ -951,6 +939,8 @@ void StreamChecker::evalFopen(const FnDescription *Desc, const CallEvent &Call,
951
939
StateNull =
952
940
StateNull->set <StreamMap>(RetSym, StreamState::getOpenFailed (Desc));
953
941
942
+ StateNotNull = assumeNoAliasingWithStdStreams (StateNotNull, RetVal, C);
943
+
954
944
C.addTransition (StateNotNull,
955
945
constructLeakNoteTag (C, RetSym, " Stream opened here" ));
956
946
C.addTransition (StateNull);
@@ -2081,10 +2071,12 @@ getGlobalStreamPointerByName(const TranslationUnitDecl *TU, StringRef VarName) {
2081
2071
}
2082
2072
2083
2073
void StreamChecker::checkASTDecl (const TranslationUnitDecl *TU,
2084
- AnalysisManager &, BugReporter &) const {
2074
+ AnalysisManager &Mgr , BugReporter &) const {
2085
2075
StdinDecl = getGlobalStreamPointerByName (TU, " stdin" );
2086
2076
StdoutDecl = getGlobalStreamPointerByName (TU, " stdout" );
2087
2077
StderrDecl = getGlobalStreamPointerByName (TU, " stderr" );
2078
+ VaListType = TU->getASTContext ().getBuiltinVaListType ().getCanonicalType ();
2079
+ initMacroValues (Mgr.getPreprocessor ());
2088
2080
}
2089
2081
2090
2082
// ===----------------------------------------------------------------------===//
0 commit comments