Skip to content

Commit 356445d

Browse files
committed
Fix
1 parent a007659 commit 356445d

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎lib/astutils.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2794,7 +2794,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings,
27942794
const Token * ptok = tok2;
27952795
while (Token::Match(ptok->astParent(), ".|::"))
27962796
ptok = ptok->astParent();
2797-
int pindirect = indirect - derefs;
2797+
int pindirect = std::max(indirect - derefs, 0);
27982798
if (indirect == 0 && astIsLHS(tok2) && Token::Match(ptok, ". %var%") && astIsPointer(ptok->next()))
27992799
pindirect = 1;
28002800
bool inconclusive = false;

‎test/testother.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10514,6 +10514,14 @@ class TestOther : public TestFixture {
1051410514
" return m.trace();\n"
1051510515
"}\n");
1051610516
ASSERT_EQUALS("", errout_str());
10517+
10518+
check("std::string f(const std::string& s) {\n"
10519+
" std::string u = s;\n"
10520+
" std::string::iterator i = u.begin();\n"
10521+
" *i = toupper(*i);\n"
10522+
" return u;\n"
10523+
"}\n");
10524+
ASSERT_EQUALS("", errout_str());
1051710525
}
1051810526

1051910527
void checkNegativeShift() {

0 commit comments

Comments
 (0)