Skip to content

Commit c9eb6d8

Browse files
committed
[clang-tidy] Fix broken fix-its with bugprone-not-null-terminated-result on Windows
1 parent 97cf55b commit c9eb6d8

File tree

4 files changed

+7
-14
lines changed

4 files changed

+7
-14
lines changed

clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,9 @@ static void lengthExprHandle(const Expr *LengthExpr,
307307
// Try to obtain an 'IntegerLiteral' and adjust it.
308308
if (!IsMacroDefinition) {
309309
if (const auto *LengthIL = dyn_cast<IntegerLiteral>(LengthExpr)) {
310-
size_t NewLength = LengthIL->getValue().getZExtValue() +
311-
(LengthHandle == LengthHandleKind::Increase
312-
? (isInjectUL(Result) ? 1UL : 1)
313-
: -1);
310+
uint64_t NewLength =
311+
LengthIL->getValue().getZExtValue() +
312+
(LengthHandle == LengthHandleKind::Increase ? 1 : -1);
314313

315314
const auto NewLengthFix = FixItHint::CreateReplacement(
316315
LengthIL->getSourceRange(),

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ Changes in existing checks
274274
<clang-tidy/checks/bugprone/narrowing-conversions>` check by fixing
275275
false positive from analysis of a conditional expression in C.
276276

277+
- Improved :doc:`bugprone-not-null-terminated-result
278+
<clang-tidy/checks/bugprone/not-null-terminated-result>` check by fixing
279+
bogus fix-its for `strncmp` and `wcsncmp` on Windows.
280+
277281
- Improved :doc:`bugprone-reserved-identifier
278282
<clang-tidy/checks/bugprone/reserved-identifier>` check by ignoring
279283
declarations and macros in system headers.

clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-strlen.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
// RUN: %check_clang_tidy --match-partial-fixes %s bugprone-not-null-terminated-result %t -- \
22
// RUN: -- -I %S/Inputs/not-null-terminated-result
33

4-
// FIXME: Something wrong with the APInt un/signed conversion on Windows:
5-
// in 'strncmp(str6, "string", 7);' it tries to inject '4294967302' as length.
6-
7-
// UNSUPPORTED: system-windows
8-
94
#include "not-null-terminated-result-c.h"
105

116
#define __STDC_LIB_EXT1__ 1

clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-wcslen.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
// RUN: %check_clang_tidy --match-partial-fixes %s bugprone-not-null-terminated-result %t -- \
22
// RUN: -- -std=c++11 -I %S/Inputs/not-null-terminated-result
33

4-
// FIXME: Something wrong with the APInt un/signed conversion on Windows:
5-
// in 'wcsncmp(wcs6, L"string", 7);' it tries to inject '4294967302' as length.
6-
7-
// UNSUPPORTED: system-windows
8-
94
#include "not-null-terminated-result-cxx.h"
105

116
#define __STDC_LIB_EXT1__ 1

0 commit comments

Comments
 (0)