This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix a crash in bugprone-not-null-terminated-result check when `__STDC_WANT_LIB_EXT1__` was undefined after definition.
ClosedPublic

Authored by ArcsinX on Aug 7 2020, 6:55 AM.

Details

Summary

PP->getMacroInfo() returns nullptr for undefined macro, so we need to check this return value before dereference.
Stack dump:

#0 0x0000000002185e6a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/llvm-project/build/bin/clang-tidy+0x2185e6a)
#1 0x0000000002183e8c llvm::sys::RunSignalHandlers() (/llvm-project/build/bin/clang-tidy+0x2183e8c)
#2 0x0000000002183ff3 SignalHandler(int) (/llvm-project/build/bin/clang-tidy+0x2183ff3)
#3 0x00007f37df9b1390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
#4 0x000000000052054e clang::tidy::bugprone::NotNullTerminatedResultCheck::check(clang::ast_matchers::MatchFinder::MatchResult const&) (/llvm-project/build/bin/clang-tidy+0x52054e)

Diff Detail

Event Timeline

ArcsinX created this revision.Aug 7 2020, 6:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 7 2020, 6:55 AM
ArcsinX requested review of this revision.Aug 7 2020, 6:55 AM
ArcsinX added a project: Restricted Project.
hokein accepted this revision.Aug 7 2020, 7:23 AM
hokein added inline comments.
clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-undef-stdc-want-lib-ext1.c
4

The same here.

This revision is now accepted and ready to land.Aug 7 2020, 7:23 AM
Eugene.Zelenko added inline comments.
clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-undef-stdc-want-lib-ext1.c
18

Please add newline.