Skip to content

Commit 3f9f522

Browse files
authored
[clang-tidy] Fix broken fix-its with bugprone-not-null-terminated-result on Windows (#162874)
(See the test changes for a description of the problem.)
1 parent 65fe2d1 commit 3f9f522

File tree

4 files changed

+4
-14
lines changed

4 files changed

+4
-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
@@ -309,10 +309,9 @@ static void lengthExprHandle(const Expr *LengthExpr,
309309
// Try to obtain an 'IntegerLiteral' and adjust it.
310310
if (!IsMacroDefinition) {
311311
if (const auto *LengthIL = dyn_cast<IntegerLiteral>(LengthExpr)) {
312-
size_t NewLength = LengthIL->getValue().getZExtValue() +
313-
(LengthHandle == LengthHandleKind::Increase
314-
? (isInjectUL(Result) ? 1UL : 1)
315-
: -1);
312+
uint64_t NewLength =
313+
LengthIL->getValue().getZExtValue() +
314+
(LengthHandle == LengthHandleKind::Increase ? 1 : -1);
316315

317316
const auto NewLengthFix = FixItHint::CreateReplacement(
318317
LengthIL->getSourceRange(),

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ Changes in existing checks
276276

277277
- Improved :doc:`bugprone-not-null-terminated-result
278278
<clang-tidy/checks/bugprone/not-null-terminated-result>` check by fixing
279+
bogus fix-its for ``strncmp`` and ``wcsncmp`` on Windows and
279280
a crash caused by certain value-dependent expressions.
280281

281282
- Improved :doc:`bugprone-reserved-identifier

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 %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 -std=c++11-or-later %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 '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)