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

Method isCtuUnsafeBufferUsage

lib/checkbufferoverrun.cpp:925–944  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

923}
924
925bool CheckBufferOverrunImpl::isCtuUnsafeBufferUsage(const Settings &settings, const Token *argtok, CTU::FileInfo::Value *offset, int type)
926{
927 if (!offset)
928 return false;
929 if (!argtok->valueType() || argtok->valueType()->getSizeOf(settings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointee) == 0)
930 return false;
931 const Token *indexTok = nullptr;
932 if (type == 1 && Token::Match(argtok, "%name% [") && argtok->astParent() == argtok->next() && !Token::simpleMatch(argtok->linkAt(1), "] ["))
933 indexTok = argtok->next()->astOperand2();
934 else if (type == 2 && Token::simpleMatch(argtok->astParent(), "+"))
935 indexTok = (argtok == argtok->astParent()->astOperand1()) ?
936 argtok->astParent()->astOperand2() :
937 argtok->astParent()->astOperand1();
938 if (!indexTok)
939 return false;
940 if (!indexTok->hasKnownIntValue())
941 return false;
942 offset->value = indexTok->getKnownIntValue() * argtok->valueType()->getSizeOf(settings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointee);
943 return true;
944}
945
946bool CheckBufferOverrunImpl::isCtuUnsafeArrayIndex(const Settings &settings, const Token *argtok, CTU::FileInfo::Value *offset)
947{

Callers

nothing calls this directly

Calls 9

getSizeOfMethod · 0.80
astParentMethod · 0.80
nextMethod · 0.80
linkAtMethod · 0.80
astOperand2Method · 0.80
astOperand1Method · 0.80
getKnownIntValueMethod · 0.80
simpleMatchFunction · 0.70
hasKnownIntValueMethod · 0.45

Tested by

no test coverage detected