[PATCH] D85525: [clang-tidy] Fix a crash in bugprone-not-null-terminated-result check when `__STDC_WANT_LIB_EXT1__` is not a literal.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 7 07:15:18 PDT 2020
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.
================
Comment at: clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp:806
const auto &T = MI->tokens().back();
- StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
- llvm::APInt IntValue;
- ValueStr.getAsInteger(10, IntValue);
- AreSafeFunctionsWanted = IntValue.getZExtValue();
+ if (T.isLiteral()) {
+ StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
----------------
let's add the `getLiteralData` check here -- `if (T.isLiteral() && T.getLiteralData())`
================
Comment at: clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-stdc-want-lib-ext1-not-a-literal.c:3
+// RUN: -- -std=c11 -I %S/Inputs/bugprone-not-null-terminated-result
+
+#include "not-null-terminated-result-c.h"
----------------
I think you probably need a `// UNSUPPORTED: system-windows`, as the `bugprone-not-null-terminated-result-strlen.c` does.
================
Comment at: clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-stdc-want-lib-ext1-not-a-literal.c:16
+}
\ No newline at end of file
----------------
nit: add EOF.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85525/new/
https://reviews.llvm.org/D85525
More information about the cfe-commits
mailing list