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

Method memsetZeroBytes

lib/checkfunctions.cpp:522–549  ·  view source on GitHub ↗

--------------------------------------------------------------------------- memset(p, y, 0 /* bytes to fill */) <- 2nd and 3rd arguments inverted ---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

520// memset(p, y, 0 /* bytes to fill */) <- 2nd and 3rd arguments inverted
521//---------------------------------------------------------------------------
522void CheckFunctionsImpl::memsetZeroBytes()
523{
524// FIXME:
525// Replace this with library configuration.
526// For instance:
527// <arg nr="3">
528// <warn knownIntValue="0" severity="warning" msg="..."/>
529// </arg>
530
531 if (!mSettings.severity.isEnabled(Severity::warning))
532 return;
533
534 logChecker("CheckFunctions::memsetZeroBytes"); // warning
535
536 const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
537 for (const Scope *scope : symbolDatabase->functionScopes) {
538 for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
539 if (Token::Match(tok, "memset|wmemset (") && (numberOfArguments(tok)==3)) {
540 const std::vector<const Token *> &arguments = getArguments(tok);
541 if (WRONG_DATA(arguments.size() != 3U, tok))
542 continue;
543 const Token* lastParamTok = arguments[2];
544 if (MathLib::isNullValue(lastParamTok->str()))
545 memsetZeroBytesError(tok);
546 }
547 }
548 }
549}
550
551void CheckFunctionsImpl::memsetZeroBytesError(const Token *tok)
552{

Callers 1

runChecksMethod · 0.45

Calls 6

numberOfArgumentsFunction · 0.85
nextMethod · 0.80
getArgumentsFunction · 0.70
isEnabledMethod · 0.45
sizeMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected