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

Function indexValueString

lib/checkstl.cpp:201–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199}
200
201static std::string indexValueString(const ValueFlow::Value& indexValue, const std::string& containerName = "")
202{
203 if (indexValue.isIteratorStartValue())
204 return "at position " + MathLib::toString(indexValue.intvalue) + " from the beginning";
205 if (indexValue.isIteratorEndValue())
206 return "at position " + MathLib::toString(-indexValue.intvalue) + " from the end";
207 std::string indexString = MathLib::toString(indexValue.intvalue);
208 if (indexValue.isSymbolicValue()) {
209 indexString = containerName + ".size()";
210 if (indexValue.intvalue != 0)
211 indexString += "+" + MathLib::toString(indexValue.intvalue);
212 }
213 if (indexValue.bound == ValueFlow::Value::Bound::Lower)
214 return "greater or equal to " + indexString;
215 return indexString;
216}
217
218void CheckStlImpl::outOfBoundsError(const Token *tok, const std::string &containerName, const ValueFlow::Value *containerSize, const std::string &index, const ValueFlow::Value *indexValue)
219{

Callers 1

outOfBoundsErrorMethod · 0.85

Calls 1

toStringFunction · 0.70

Tested by

no test coverage detected