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

Method pointerassignment

lib/check64bit.cpp:54–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54void Check64BitPortabilityImpl::pointerassignment()
55{
56 if (!mSettings.severity.isEnabled(Severity::portability))
57 return;
58
59 logChecker("Check64BitPortability::pointerassignment"); // portability
60
61 const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
62
63 // Check return values
64 for (const Scope * scope : symbolDatabase->functionScopes) {
65 if (scope->function == nullptr || !scope->function->hasBody()) // We only look for functions with a body
66 continue;
67
68 bool retPointer = false;
69 if (scope->function->token->strAt(-1) == "*") // Function returns a pointer
70 retPointer = true;
71 else if (is32BitIntegerReturn(scope->function, mSettings))
72 ;
73 else
74 continue;
75
76 for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
77 // skip nested functions
78 if (tok->str() == "{") {
79 if (tok->scope()->type == ScopeType::eFunction || tok->scope()->type == ScopeType::eLambda)
80 tok = tok->link();
81 }
82
83 if (tok->str() != "return")
84 continue;
85
86 if (!tok->astOperand1() || tok->astOperand1()->isNumber())
87 continue;
88
89 const ValueType * const returnType = tok->astOperand1()->valueType();
90 if (!returnType)
91 continue;
92
93 if (retPointer && !returnType->typeScope && returnType->pointer == 0U)
94 returnIntegerError(tok);
95
96 if (!retPointer) {
97 bool warn = returnType->pointer >= 1U;
98 if (!warn) {
99 const Token* tok2 = tok->astOperand1();
100 while (tok2 && tok2->isCast())
101 tok2 = tok2->astOperand2() ? tok2->astOperand2() : tok2->astOperand1();
102 warn = tok2 && tok2->valueType() && tok2->valueType()->pointer;
103 }
104 if (warn)
105 returnPointerError(tok);
106 }
107 }
108 }
109
110 // Check assignments
111 for (const Scope * scope : symbolDatabase->functionScopes) {

Callers 2

runChecksMethod · 0.80
check_Method · 0.80

Calls 11

is32BitIntegerReturnFunction · 0.85
isFunctionPointerFunction · 0.85
nextMethod · 0.80
scopeMethod · 0.80
astOperand1Method · 0.80
isCastMethod · 0.80
astOperand2Method · 0.80
isIntegralMethod · 0.80
isEnabledMethod · 0.45
strMethod · 0.45
emptyMethod · 0.45

Tested by 1

check_Method · 0.64