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

Method warningDangerousTypeCast

lib/checkother.cpp:408–434  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

406}
407
408void CheckOtherImpl::warningDangerousTypeCast()
409{
410 // Only valid on C++ code
411 if (!mTokenizer->isCPP())
412 return;
413 if (!mSettings.severity.isEnabled(Severity::warning) && !mSettings.isPremiumEnabled("dangerousTypeCast"))
414 return;
415
416 logChecker("CheckOther::warningDangerousTypeCast"); // warning,c++
417
418 const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
419 for (const Scope * scope : symbolDatabase->functionScopes) {
420 const Token* tok;
421 if (scope->function && scope->function->isConstructor())
422 tok = scope->classDef;
423 else
424 tok = scope->bodyStart;
425 for (; tok && tok != scope->bodyEnd; tok = tok->next()) {
426 // Old style pointer casting..
427 if (!tok->isCast() || tok->isBinaryOp())
428 continue;
429
430 if (isDangerousTypeConversion(tok))
431 dangerousTypeCastError(tok, tok->valueType()->pointer > 0);
432 }
433 }
434}
435
436void CheckOtherImpl::dangerousTypeCastError(const Token *tok, bool isPtr)
437{

Callers 2

runChecksMethod · 0.80

Calls 7

isCPPMethod · 0.80
isPremiumEnabledMethod · 0.80
nextMethod · 0.80
isCastMethod · 0.80
isBinaryOpMethod · 0.80
isEnabledMethod · 0.45

Tested by 1