Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,9 @@ static void lengthExprHandle(const Expr *LengthExpr,
// Try to obtain an 'IntegerLiteral' and adjust it.
if (!IsMacroDefinition) {
if (const auto *LengthIL = dyn_cast<IntegerLiteral>(LengthExpr)) {
size_t NewLength = LengthIL->getValue().getZExtValue() +
(LengthHandle == LengthHandleKind::Increase
? (isInjectUL(Result) ? 1UL : 1)
: -1);
uint64_t NewLength =
LengthIL->getValue().getZExtValue() +
(LengthHandle == LengthHandleKind::Increase ? 1 : -1);

const auto NewLengthFix = FixItHint::CreateReplacement(
LengthIL->getSourceRange(),
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ Changes in existing checks
<clang-tidy/checks/bugprone/narrowing-conversions>` check by fixing
false positive from analysis of a conditional expression in C.

- Improved :doc:`bugprone-not-null-terminated-result
<clang-tidy/checks/bugprone/not-null-terminated-result>` check by fixing
bogus fix-its for ``strncmp`` and ``wcsncmp`` on Windows.

- Improved :doc:`bugprone-reserved-identifier
<clang-tidy/checks/bugprone/reserved-identifier>` check by ignoring
declarations and macros in system headers.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// RUN: %check_clang_tidy --match-partial-fixes %s bugprone-not-null-terminated-result %t -- \
// RUN: -- -I %S/Inputs/not-null-terminated-result

// FIXME: Something wrong with the APInt un/signed conversion on Windows:
// in 'strncmp(str6, "string", 7);' it tries to inject '4294967302' as length.

// UNSUPPORTED: system-windows

#include "not-null-terminated-result-c.h"

#define __STDC_LIB_EXT1__ 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// RUN: %check_clang_tidy --match-partial-fixes %s bugprone-not-null-terminated-result %t -- \
// RUN: -- -std=c++11 -I %S/Inputs/not-null-terminated-result

// FIXME: Something wrong with the APInt un/signed conversion on Windows:
// in 'wcsncmp(wcs6, L"string", 7);' it tries to inject '4294967302' as length.

// UNSUPPORTED: system-windows

#include "not-null-terminated-result-cxx.h"

#define __STDC_LIB_EXT1__ 1
Expand Down