Skip to content

Commit 26423cb

Browse files
Remove redundant invalidation in scanf
1 parent be2b63e commit 26423cb

File tree

2 files changed

+9
-28
lines changed

2 files changed

+9
-28
lines changed

clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -180,27 +180,6 @@ struct FnDescription {
180180
ArgNoTy StreamArgNo;
181181
};
182182

183-
[[nodiscard]] ProgramStateRef
184-
escapeArgsStartingFromIndex(ProgramStateRef State, CheckerContext &C,
185-
const CallEvent &Call,
186-
unsigned FirstEscapingArgIndex) {
187-
const auto *CE = Call.getOriginExpr();
188-
assert(CE);
189-
190-
if (Call.getNumArgs() <= FirstEscapingArgIndex)
191-
return State;
192-
193-
SmallVector<SVal> EscapingArgs;
194-
EscapingArgs.reserve(Call.getNumArgs() - FirstEscapingArgIndex);
195-
for (auto EscArgIdx :
196-
llvm::seq<int>(FirstEscapingArgIndex, Call.getNumArgs()))
197-
EscapingArgs.push_back(Call.getArgSVal(EscArgIdx));
198-
State = State->invalidateRegions(EscapingArgs, CE, C.blockCount(),
199-
C.getLocationContext(),
200-
/*CausesPointerEscape=*/false);
201-
return State;
202-
}
203-
204183
/// Get the value of the stream argument out of the passed call event.
205184
/// The call should contain a function that is described by Desc.
206185
SVal getStreamArg(const FnDescription *Desc, const CallEvent &Call) {
@@ -1054,10 +1033,6 @@ void StreamChecker::evalFscanf(const FnDescription *Desc, const CallEvent &Call,
10541033
if (!E.Init(Desc, Call, C, State))
10551034
return;
10561035

1057-
// The pointers passed to fscanf escape and get invalidated.
1058-
State =
1059-
escapeArgsStartingFromIndex(State, C, Call, /*FirstEscapingArgIndex=*/2);
1060-
10611036
// Add the success state.
10621037
// In this context "success" means there is not an EOF or other read error
10631038
// before any item is matched in 'fscanf'. But there may be match failure,

clang/test/Analysis/stream.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,15 @@ void test_fscanf_escape() {
391391
clang_analyzer_dump_char(buffer[2]); // expected-warning {{67 S8b}}
392392

393393
int ret = fscanf(F1, "%d %u %s", &a, &b, buffer);
394-
clang_analyzer_dump_int(a); // expected-warning {{conj_$}}
395-
clang_analyzer_dump_int(b); // expected-warning {{conj_$}}
396-
clang_analyzer_dump_char(buffer[2]); // expected-warning {{derived_$}}
394+
if (ret != EOF) {
395+
clang_analyzer_dump_int(a); // expected-warning {{conj_$}}
396+
clang_analyzer_dump_int(b); // expected-warning {{conj_$}}
397+
clang_analyzer_dump_char(buffer[2]); // expected-warning {{derived_$}}
398+
} else {
399+
clang_analyzer_dump_int(a); // expected-warning {{48 S32b}}
400+
clang_analyzer_dump_int(b); // expected-warning {{127 S32b}}
401+
clang_analyzer_dump_char(buffer[2]); // expected-warning {{67 S8b}}
402+
}
397403

398404
if (ret != EOF) {
399405
char c = fgetc(F1); // ok

0 commit comments

Comments
 (0)