Fix leakNoVarFunctionCall FP (#4523)
This commit is contained in:
parent
5f79f0ccad
commit
6142ba542a
|
@ -4976,7 +4976,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
|
|||
</function>
|
||||
<!-- char *strncpy(char *s, const char *ct, size_t n); -->
|
||||
<function name="strncpy,std::strncpy">
|
||||
<returnValue type="char *"/>
|
||||
<returnValue type="char *">arg1</returnValue>
|
||||
<noreturn>false</noreturn>
|
||||
<leak-ignore/>
|
||||
<not-overlapping-data ptr1-arg="1" ptr2-arg="2" size-arg="3"/>
|
||||
|
|
|
@ -997,9 +997,9 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope)
|
|||
|
||||
// check if the output of the function is assigned
|
||||
const Token* tok2 = tok->next()->astParent();
|
||||
while (tok2 && tok2->isCast())
|
||||
while (tok2 && (tok2->isCast() || Token::Match(tok2, "?|:")))
|
||||
tok2 = tok2->astParent();
|
||||
if (Token::Match(tok2, "%assign%"))
|
||||
if (Token::Match(tok2, "%assign%")) // TODO: check if function returns allocated resource
|
||||
continue;
|
||||
if (Token::simpleMatch(tok->astTop(), "return"))
|
||||
continue;
|
||||
|
|
|
@ -2446,6 +2446,12 @@ private:
|
|||
" u.reset(strcpy(new char[n], s.c_str()));\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("struct S { char* p; };\n"
|
||||
"void f(S* s, int N) {\n"
|
||||
" s->p = s->p ? strcpy(new char[N], s->p) : nullptr;\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void missingAssignment() {
|
||||
|
|
Loading…
Reference in New Issue