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

Method warningIntToPointerCast

lib/checkother.cpp:445–472  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

443}
444
445void CheckOtherImpl::warningIntToPointerCast()
446{
447 if (!mSettings.severity.isEnabled(Severity::portability) && !mSettings.isPremiumEnabled("cstyleCast"))
448 return;
449
450 logChecker("CheckOther::warningIntToPointerCast"); // portability
451
452 for (const Token* tok = mTokenizer->tokens(); tok; tok = tok->next()) {
453 // pointer casting..
454 if (!tok->isCast())
455 continue;
456 const Token* from = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1();
457 if (!from || !from->isNumber())
458 continue;
459 if (!tok->valueType() || tok->valueType()->pointer == 0)
460 continue;
461 if (!MathLib::isIntHex(from->str()) && from->hasKnownIntValue() && from->getKnownIntValue() != 0) {
462 std::string format;
463 if (MathLib::isDec(from->str()))
464 format = "decimal";
465 else if (MathLib::isOct(from->str()))
466 format = "octal";
467 else
468 continue;
469 intToPointerCastError(tok, format);
470 }
471 }
472}
473
474void CheckOtherImpl::intToPointerCastError(const Token *tok, const std::string& format)
475{

Callers 2

runChecksMethod · 0.80

Calls 10

isOctFunction · 0.85
isPremiumEnabledMethod · 0.80
nextMethod · 0.80
isCastMethod · 0.80
astOperand2Method · 0.80
astOperand1Method · 0.80
getKnownIntValueMethod · 0.80
isEnabledMethod · 0.45
strMethod · 0.45
hasKnownIntValueMethod · 0.45

Tested by 1