Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 442952a

Browse files
author
Csaba Dabis
committed
[clang-tidy] bugprone-not-null-terminated-result: checker adjustments 2
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@374712 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d2410d2 commit 442952a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ static const Expr *getDestCapacityExpr(const MatchFinder::MatchResult &Result) {
5959

6060
// Returns the length of \p E as an 'IntegerLiteral' or a 'StringLiteral'
6161
// without the null-terminator.
62-
static int getLength(const Expr *E, const MatchFinder::MatchResult &Result) {
62+
static unsigned getLength(const Expr *E,
63+
const MatchFinder::MatchResult &Result) {
6364
if (!E)
6465
return 0;
6566

@@ -71,10 +72,10 @@ static int getLength(const Expr *E, const MatchFinder::MatchResult &Result) {
7172
if (!isa<ParmVarDecl>(LengthVD))
7273
if (const Expr *LengthInit = LengthVD->getInit())
7374
if (LengthInit->EvaluateAsInt(Length, *Result.Context))
74-
return Length.Val.getInt().getSExtValue();
75+
return Length.Val.getInt().getZExtValue();
7576

7677
if (const auto *LengthIL = dyn_cast<IntegerLiteral>(E))
77-
return LengthIL->getValue().getSExtValue();
78+
return LengthIL->getValue().getZExtValue();
7879

7980
if (const auto *StrDRE = dyn_cast<DeclRefExpr>(E))
8081
if (const auto *StrVD = dyn_cast<VarDecl>(StrDRE->getDecl()))
@@ -306,7 +307,7 @@ static void lengthExprHandle(const Expr *LengthExpr,
306307
// Try to obtain an 'IntegerLiteral' and adjust it.
307308
if (!IsMacroDefinition) {
308309
if (const auto *LengthIL = dyn_cast<IntegerLiteral>(LengthExpr)) {
309-
size_t NewLength = LengthIL->getValue().getSExtValue() +
310+
size_t NewLength = LengthIL->getValue().getZExtValue() +
310311
(LengthHandle == LengthHandleKind::Increase
311312
? (isInjectUL(Result) ? 1UL : 1)
312313
: -1);
@@ -327,7 +328,7 @@ static void lengthExprHandle(const Expr *LengthExpr,
327328
const Expr *RhsExpr = BO->getRHS()->IgnoreImpCasts();
328329

329330
if (const auto *LhsIL = dyn_cast<IntegerLiteral>(LhsExpr)) {
330-
if (LhsIL->getValue().getSExtValue() == 1) {
331+
if (LhsIL->getValue().getZExtValue() == 1) {
331332
Diag << FixItHint::CreateRemoval(
332333
{LhsIL->getBeginLoc(),
333334
RhsExpr->getBeginLoc().getLocWithOffset(-1)});
@@ -336,7 +337,7 @@ static void lengthExprHandle(const Expr *LengthExpr,
336337
}
337338

338339
if (const auto *RhsIL = dyn_cast<IntegerLiteral>(RhsExpr)) {
339-
if (RhsIL->getValue().getSExtValue() == 1) {
340+
if (RhsIL->getValue().getZExtValue() == 1) {
340341
Diag << FixItHint::CreateRemoval(
341342
{LhsExpr->getEndLoc().getLocWithOffset(1), RhsIL->getEndLoc()});
342343
return;
@@ -803,7 +804,7 @@ void NotNullTerminatedResultCheck::check(
803804
StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
804805
llvm::APInt IntValue;
805806
ValueStr.getAsInteger(10, IntValue);
806-
AreSafeFunctionsWanted = IntValue.getSExtValue();
807+
AreSafeFunctionsWanted = IntValue.getZExtValue();
807808
}
808809

809810
++It;

0 commit comments

Comments
 (0)