Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 6 additions & 6 deletions externals/simplecpp/simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2516,7 +2516,7 @@ static void simplifySizeof(simplecpp::TokenList &expr, const std::map<std::strin
if (!tok1) {
throw std::runtime_error("missing sizeof argument");
}
simplecpp::Token *tok2 = tok1->next;
const simplecpp::Token *tok2 = tok1->next;
if (!tok2) {
throw std::runtime_error("missing sizeof argument");
}
Expand All @@ -2531,7 +2531,7 @@ static void simplifySizeof(simplecpp::TokenList &expr, const std::map<std::strin
}

std::string type;
for (simplecpp::Token *typeToken = tok1; typeToken != tok2; typeToken = typeToken->next) {
for (const simplecpp::Token *typeToken = tok1; typeToken != tok2; typeToken = typeToken->next) {
if ((typeToken->str() == "unsigned" || typeToken->str() == "signed") && typeToken->next->name)
continue;
if (typeToken->str() == "*" && type.find('*') != std::string::npos)
Expand Down Expand Up @@ -2582,11 +2582,11 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) {
if (tok->str() != HAS_INCLUDE)
continue;
simplecpp::Token *tok1 = tok->next;
const simplecpp::Token *tok1 = tok->next;
if (!tok1) {
throw std::runtime_error("missing __has_include argument");
}
simplecpp::Token *tok2 = tok1->next;
const simplecpp::Token *tok2 = tok1->next;
if (!tok2) {
throw std::runtime_error("missing __has_include argument");
}
Expand All @@ -2604,7 +2604,7 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
const bool systemheader = (tok1 && tok1->op == '<');
std::string header;
if (systemheader) {
simplecpp::Token *tok3 = tok1->next;
const simplecpp::Token *tok3 = tok1->next;
if (!tok3) {
throw std::runtime_error("missing __has_include closing angular bracket");
}
Expand All @@ -2615,7 +2615,7 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
}
}

for (simplecpp::Token *headerToken = tok1->next; headerToken != tok3; headerToken = headerToken->next)
for (const simplecpp::Token *headerToken = tok1->next; headerToken != tok3; headerToken = headerToken->next)
header += headerToken->str();
} else {
header = tok1->str().substr(1U, tok1->str().size() - 2U);
Expand Down
4 changes: 2 additions & 2 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,7 @@ void CheckOther::checkConstPointer()
if (lhs && lhs->variable() && lhs->variable()->isReference() && lhs->variable()->nameToken() == lhs && !lhs->variable()->isConst())
takingRef = true;
if (lhs && lhs->valueType() && lhs->valueType()->pointer && (lhs->valueType()->constness & 1) == 0 &&
parent->valueType() && parent->valueType()->pointer)
parent->valueType() && parent->valueType()->pointer && lhs->variable() != var)
nonConstPtrAssignment = true;
if (!takingRef && !nonConstPtrAssignment)
continue;
Expand All @@ -1910,7 +1910,7 @@ void CheckOther::checkConstPointer()
}
} else {
int argn = -1;
if (Token::Match(parent, "%oror%|%comp%|&&|?|!|-|<<"))
if (Token::Match(parent, "%oror%|%comp%|&&|?|!|-|<<|;"))
continue;
if (hasIncDecPlus && !parent->astParent())
continue;
Expand Down
2 changes: 1 addition & 1 deletion lib/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2669,7 +2669,7 @@ void TokenImpl::setCppcheckAttribute(TokenImpl::CppcheckAttributes::Type type, M

bool TokenImpl::getCppcheckAttribute(TokenImpl::CppcheckAttributes::Type type, MathLib::bigint &value) const
{
CppcheckAttributes *attr = mCppcheckAttributes;
const CppcheckAttributes *attr = mCppcheckAttributes;
Comment thread
chrchr-github marked this conversation as resolved.
while (attr && attr->type != type)
attr = attr->next;
if (attr)
Expand Down
14 changes: 14 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4497,6 +4497,20 @@ class TestOther : public TestFixture {
ASSERT_EQUALS("[test.cpp:2:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n"
"[test.cpp:5:18]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n",
errout_str());

check("struct S { S* next; };\n" // #14119
"void f(S* s) {\n"
" for (S* p = s->next; p != nullptr; p = p->next) {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3:13]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\n",
errout_str());

check("void f(int* p) {\n"
" for (int* q = p; q;)\n"
" break;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2:15]: (style) Variable 'q' can be declared as pointer to const [constVariablePointer]\n",
errout_str());
}

void constArray() {
Expand Down