This is an archive of the discontinued LLVM Phabricator instance.

[NFC][clang][analyzer] Avoid potential dereferencing of null pointer value
Needs RevisionPublic

Authored by Manna on Aug 18 2023, 10:34 AM.

Diff Detail

Event Timeline

Manna created this revision.Aug 18 2023, 10:34 AM
Herald added a project: Restricted Project. · View Herald Transcript
Manna requested review of this revision.Aug 18 2023, 10:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2023, 10:34 AM
steakhal requested changes to this revision.Aug 18 2023, 11:11 AM

Thanks for the PR.
I went over the code and concluded that it can never be null.
However, the code could be improved, while making this explicit.

clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
1416–1433

So state->get<RefBindings>() returns a map, and we iterate over the Key&Val pairs of that map.

const RefVal *getRefBinding(ProgramStateRef State, SymbolRef Sym) {
  return State->get<RefBindings>(Sym);
}

So, this just returns the associated value with Sym in the map.
Instead of this lookup ,we really should have just used the I.second.

Now the question is, could have map a Sym to a null pointer?

static ProgramStateRef setRefBinding(ProgramStateRef State, SymbolRef Sym,
                                     RefVal Val) {
  assert(Sym != nullptr);
  return State->set<RefBindings>(Sym, Val);
}

Nop. It's never supposed to be null.


Could you please just decompose in the loop with a structured-binding to auto [Sym, V] and use V instead of T?

This revision now requires changes to proceed.Aug 18 2023, 11:11 AM