File tree 2 files changed +22
-4
lines changed
2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -805,10 +805,12 @@ void NotNullTerminatedResultCheck::check(
805
805
// PP->getMacroInfo() returns nullptr if macro has no definition.
806
806
if (MI) {
807
807
const auto &T = MI->tokens ().back ();
808
- StringRef ValueStr = StringRef (T.getLiteralData (), T.getLength ());
809
- llvm::APInt IntValue;
810
- ValueStr.getAsInteger (10 , IntValue);
811
- AreSafeFunctionsWanted = IntValue.getZExtValue ();
808
+ if (T.isLiteral () && T.getLiteralData ()) {
809
+ StringRef ValueStr = StringRef (T.getLiteralData (), T.getLength ());
810
+ llvm::APInt IntValue;
811
+ ValueStr.getAsInteger (10 , IntValue);
812
+ AreSafeFunctionsWanted = IntValue.getZExtValue ();
813
+ }
812
814
}
813
815
}
814
816
Original file line number Diff line number Diff line change
1
+ // RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \
2
+ // RUN: -- -std=c11 -I %S/Inputs/bugprone-not-null-terminated-result
3
+
4
+ #include "not-null-terminated-result-c.h"
5
+
6
+ #define __STDC_LIB_EXT1__ 1
7
+ #define __STDC_WANT_LIB_EXT1__ ((unsigned)1)
8
+
9
+ void f (const char * src ) {
10
+ char dest [13 ];
11
+ memcpy_s (dest , 13 , src , strlen (src ) - 1 );
12
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 'memcpy_s' is not null-terminated [bugprone-not-null-terminated-result]
13
+ // CHECK-FIXES: char dest[14];
14
+ // CHECK-FIXES-NEXT: strncpy_s(dest, 14, src, strlen(src) - 1);
15
+ }
16
+
You can’t perform that action at this time.
0 commit comments