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

Method arrayIndexThenCheckError

lib/checkbufferoverrun.cpp:745–754  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

743}
744
745void CheckBufferOverrunImpl::arrayIndexThenCheckError(const Token *tok, const std::string &indexName)
746{
747 reportError(tok, Severity::style, "arrayIndexThenCheck",
748 "$symbol:" + indexName + "\n"
749 "Array index '$symbol' is used before limits check.\n"
750 "Defensive programming: The variable '$symbol' is used as an array index before it "
751 "is checked that is within limits. This can mean that the array might be accessed out of bounds. "
752 "Reorder conditions such as '(a[i] && i < 10)' to '(i < 10 && a[i])'. That way the array will "
753 "not be accessed if the index is out of limits.", CWE_ARRAY_INDEX_THEN_CHECK, Certainty::normal);
754}
755
756//---------------------------------------------------------------------------
757

Callers 1

getErrorMessagesMethod · 0.80

Calls 1

reportErrorFunction · 0.70

Tested by

no test coverage detected