diff options
author | Csaba Dabis <dabis.csaba98@gmail.com> | 2019-10-13 10:20:58 +0000 |
---|---|---|
committer | Csaba Dabis <dabis.csaba98@gmail.com> | 2019-10-13 10:20:58 +0000 |
commit | 78037577f128ff814ba09ca7f512f1f1f0f21d09 (patch) | |
tree | 55db28007f1ec8ebcec27b5ceda0e09f428d4877 | |
parent | 3965c76abccb170c99972793ac9f204500aed688 (diff) | |
download | bcm5719-llvm-78037577f128ff814ba09ca7f512f1f1f0f21d09.tar.gz bcm5719-llvm-78037577f128ff814ba09ca7f512f1f1f0f21d09.zip |
[clang-tidy] bugprone-not-null-terminated-result: checker adjustments 2
llvm-svn: 374712
-rw-r--r-- | clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp index bae772307d5..4c9b546e225 100644 --- a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp @@ -59,7 +59,8 @@ static const Expr *getDestCapacityExpr(const MatchFinder::MatchResult &Result) { // Returns the length of \p E as an 'IntegerLiteral' or a 'StringLiteral' // without the null-terminator. -static int getLength(const Expr *E, const MatchFinder::MatchResult &Result) { +static unsigned getLength(const Expr *E, + const MatchFinder::MatchResult &Result) { if (!E) return 0; @@ -71,10 +72,10 @@ static int getLength(const Expr *E, const MatchFinder::MatchResult &Result) { if (!isa<ParmVarDecl>(LengthVD)) if (const Expr *LengthInit = LengthVD->getInit()) if (LengthInit->EvaluateAsInt(Length, *Result.Context)) - return Length.Val.getInt().getSExtValue(); + return Length.Val.getInt().getZExtValue(); if (const auto *LengthIL = dyn_cast<IntegerLiteral>(E)) - return LengthIL->getValue().getSExtValue(); + return LengthIL->getValue().getZExtValue(); if (const auto *StrDRE = dyn_cast<DeclRefExpr>(E)) if (const auto *StrVD = dyn_cast<VarDecl>(StrDRE->getDecl())) @@ -306,7 +307,7 @@ 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().getSExtValue() + + size_t NewLength = LengthIL->getValue().getZExtValue() + (LengthHandle == LengthHandleKind::Increase ? (isInjectUL(Result) ? 1UL : 1) : -1); @@ -327,7 +328,7 @@ static void lengthExprHandle(const Expr *LengthExpr, const Expr *RhsExpr = BO->getRHS()->IgnoreImpCasts(); if (const auto *LhsIL = dyn_cast<IntegerLiteral>(LhsExpr)) { - if (LhsIL->getValue().getSExtValue() == 1) { + if (LhsIL->getValue().getZExtValue() == 1) { Diag << FixItHint::CreateRemoval( {LhsIL->getBeginLoc(), RhsExpr->getBeginLoc().getLocWithOffset(-1)}); @@ -336,7 +337,7 @@ static void lengthExprHandle(const Expr *LengthExpr, } if (const auto *RhsIL = dyn_cast<IntegerLiteral>(RhsExpr)) { - if (RhsIL->getValue().getSExtValue() == 1) { + if (RhsIL->getValue().getZExtValue() == 1) { Diag << FixItHint::CreateRemoval( {LhsExpr->getEndLoc().getLocWithOffset(1), RhsIL->getEndLoc()}); return; @@ -803,7 +804,7 @@ void NotNullTerminatedResultCheck::check( StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength()); llvm::APInt IntValue; ValueStr.getAsInteger(10, IntValue); - AreSafeFunctionsWanted = IntValue.getSExtValue(); + AreSafeFunctionsWanted = IntValue.getZExtValue(); } ++It; |