Fix #10729: Uncaughty exception in CheckMemoryLeak::getReallocationType() (#3717)

This commit is contained in:
Rikard Falkeborn 2022-01-18 20:50:06 +01:00 committed by GitHub
parent 1e2863cd33
commit e106654993
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -181,7 +181,10 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getReallocationType(const Token *tok
const Library::AllocFunc *f = mSettings_->library.getReallocFuncInfo(tok2);
if (!(f && f->reallocArg > 0 && f->reallocArg <= numberOfArguments(tok2)))
return No;
const Token* arg = getArguments(tok2).at(f->reallocArg - 1);
const auto args = getArguments(tok2);
if (args.size() < (f->reallocArg))
return No;
const Token* arg = args.at(f->reallocArg - 1);
while (arg && arg->isCast())
arg = arg->astOperand1();
while (arg && arg->isUnaryOp("*"))

View File

@ -2177,6 +2177,8 @@ private:
// Test getAllocationType for subfunction
TEST_CASE(getAllocationType);
TEST_CASE(crash1); // #10729
}
void functionParameter() {
@ -2565,6 +2567,18 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
}
void crash1() { // #10729
check("void foo() {\n"
" extern void *realloc (void *ptr, size_t size);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo() {\n"
" extern void *malloc (size_t size);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestMemleakNoVar)