MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / objectIndexError

Method objectIndexError

lib/checkbufferoverrun.cpp:1134–1153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1132}
1133
1134void CheckBufferOverrunImpl::objectIndexError(const Token *tok, const ValueFlow::Value *v, bool known)
1135{
1136 ErrorPath errorPath;
1137 std::string name;
1138 if (v) {
1139 const Token* expr = v->tokvalue;
1140 while (Token::simpleMatch(expr->astParent(), "."))
1141 expr = expr->astParent();
1142 name = expr->expressionString();
1143 errorPath = v->errorPath;
1144 }
1145 errorPath.emplace_back(tok, "");
1146 std::string verb = known ? "is" : "might be";
1147 reportError(std::move(errorPath),
1148 known ? Severity::error : Severity::warning,
1149 "objectIndex",
1150 "The address of variable '" + name + "' " + verb + " accessed at non-zero index.",
1151 CWE758,
1152 Certainty::normal);
1153}
1154
1155static bool isVLAIndex(const Token* tok)
1156{

Callers 1

getErrorMessagesMethod · 0.80

Calls 4

astParentMethod · 0.80
simpleMatchFunction · 0.70
reportErrorFunction · 0.70
expressionStringMethod · 0.45

Tested by

no test coverage detected