This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Fix potential dereferencing of null return value.
ClosedPublic

Authored by schittir on Jun 14 2023, 3:41 PM.

Details

Summary

Replace getAs with castAs and add assert if needed.

Diff Detail

Event Timeline

schittir created this revision.Jun 14 2023, 3:41 PM
Herald added a project: Restricted Project. · View Herald Transcript
schittir requested review of this revision.Jun 14 2023, 3:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 14 2023, 3:41 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaron.ballman accepted this revision.Jun 15 2023, 5:47 AM

LGTM with the think-o fixed.

clang/lib/Frontend/FrontendActions.cpp
461

This doesn't build. ;-)

This revision is now accepted and ready to land.Jun 15 2023, 5:47 AM
steakhal added inline comments.Jun 15 2023, 5:50 AM
clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
296–297
schittir updated this revision to Diff 531824.Jun 15 2023, 10:43 AM
schittir marked an inline comment as done.

Fix the assert causing build failure and address another review comment.

clang/lib/Frontend/FrontendActions.cpp
461

Thanks for the catch. Something was wrong with my workspace build setup, and didn't diagnose this at all! I changed this in the new patch.

schittir added inline comments.Jun 15 2023, 11:02 AM
clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
296–297

Wouldn't it be better to do an with a comment, like below?

assert(lstate && "lstate should not be null");
steakhal accepted this revision.Jun 15 2023, 11:14 AM

Looks good. Thanks!

clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
296–297

As a Static Analyzer dev I don't think its necessary. StateRefs are ubiquitous and here we probably know it cannot be null. And if it turns out to be null we would get a segfault. So that sense I don't think its necessary.

And speaking of a comment like "it should not be null" I think the segfault would sort of imply that.

schittir added inline comments.Jun 15 2023, 11:25 AM
clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
296–297

That makes sense! Thanks!

This revision was automatically updated to reflect the committed changes.