@@ -59,7 +59,8 @@ static const Expr *getDestCapacityExpr(const MatchFinder::MatchResult &Result) {
59
59
60
60
// Returns the length of \p E as an 'IntegerLiteral' or a 'StringLiteral'
61
61
// 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) {
63
64
if (!E)
64
65
return 0 ;
65
66
@@ -71,10 +72,10 @@ static int getLength(const Expr *E, const MatchFinder::MatchResult &Result) {
71
72
if (!isa<ParmVarDecl>(LengthVD))
72
73
if (const Expr *LengthInit = LengthVD->getInit ())
73
74
if (LengthInit->EvaluateAsInt (Length, *Result.Context ))
74
- return Length.Val .getInt ().getSExtValue ();
75
+ return Length.Val .getInt ().getZExtValue ();
75
76
76
77
if (const auto *LengthIL = dyn_cast<IntegerLiteral>(E))
77
- return LengthIL->getValue ().getSExtValue ();
78
+ return LengthIL->getValue ().getZExtValue ();
78
79
79
80
if (const auto *StrDRE = dyn_cast<DeclRefExpr>(E))
80
81
if (const auto *StrVD = dyn_cast<VarDecl>(StrDRE->getDecl ()))
@@ -306,7 +307,7 @@ static void lengthExprHandle(const Expr *LengthExpr,
306
307
// Try to obtain an 'IntegerLiteral' and adjust it.
307
308
if (!IsMacroDefinition) {
308
309
if (const auto *LengthIL = dyn_cast<IntegerLiteral>(LengthExpr)) {
309
- size_t NewLength = LengthIL->getValue ().getSExtValue () +
310
+ size_t NewLength = LengthIL->getValue ().getZExtValue () +
310
311
(LengthHandle == LengthHandleKind::Increase
311
312
? (isInjectUL (Result) ? 1UL : 1 )
312
313
: -1 );
@@ -327,7 +328,7 @@ static void lengthExprHandle(const Expr *LengthExpr,
327
328
const Expr *RhsExpr = BO->getRHS ()->IgnoreImpCasts ();
328
329
329
330
if (const auto *LhsIL = dyn_cast<IntegerLiteral>(LhsExpr)) {
330
- if (LhsIL->getValue ().getSExtValue () == 1 ) {
331
+ if (LhsIL->getValue ().getZExtValue () == 1 ) {
331
332
Diag << FixItHint::CreateRemoval (
332
333
{LhsIL->getBeginLoc (),
333
334
RhsExpr->getBeginLoc ().getLocWithOffset (-1 )});
@@ -336,7 +337,7 @@ static void lengthExprHandle(const Expr *LengthExpr,
336
337
}
337
338
338
339
if (const auto *RhsIL = dyn_cast<IntegerLiteral>(RhsExpr)) {
339
- if (RhsIL->getValue ().getSExtValue () == 1 ) {
340
+ if (RhsIL->getValue ().getZExtValue () == 1 ) {
340
341
Diag << FixItHint::CreateRemoval (
341
342
{LhsExpr->getEndLoc ().getLocWithOffset (1 ), RhsIL->getEndLoc ()});
342
343
return ;
@@ -803,7 +804,7 @@ void NotNullTerminatedResultCheck::check(
803
804
StringRef ValueStr = StringRef (T.getLiteralData (), T.getLength ());
804
805
llvm::APInt IntValue;
805
806
ValueStr.getAsInteger (10 , IntValue);
806
- AreSafeFunctionsWanted = IntValue.getSExtValue ();
807
+ AreSafeFunctionsWanted = IntValue.getZExtValue ();
807
808
}
808
809
809
810
++It;
0 commit comments