Skip to content

Commit f537feb

Browse files
Fix #13787 nullptr dereference in autoVariables() (danmar#7471)
Co-authored-by: chrchr-github <[email protected]>
1 parent f837929 commit f537feb

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/checkautovariables.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static bool isPtrArg(const Token *tok)
5858
static bool isArrayArg(const Token *tok, const Settings& settings)
5959
{
6060
const Variable *var = tok->variable();
61-
return (var && var->isArgument() && var->isArray() && !settings.library.isentrypoint(var->scope()->className));
61+
return (var && var->isArgument() && var->isArray() && (!var->scope() || !settings.library.isentrypoint(var->scope()->className)));
6262
}
6363

6464
static bool isArrayVar(const Token *tok)

test/testautovariables.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class TestAutoVariables : public TestFixture {
165165
TEST_CASE(invalidLifetime);
166166
TEST_CASE(deadPointer);
167167
TEST_CASE(splitNamespaceAuto); // crash #10473
168+
TEST_CASE(incompleteTypeArray);
168169
}
169170

170171

@@ -4696,6 +4697,14 @@ class TestAutoVariables : public TestFixture {
46964697
ASSERT_EQUALS("", errout_str());
46974698
}
46984699

4700+
void incompleteTypeArray() { // #13787
4701+
check("struct S (*a[10]);\n"
4702+
"void f(int i, struct S* p) {\n"
4703+
" a[i] = &p[i];\n"
4704+
"}\n");
4705+
ASSERT_EQUALS("", errout_str()); // don't crash
4706+
}
4707+
46994708
};
47004709

47014710
REGISTER_TEST(TestAutoVariables)

0 commit comments

Comments
 (0)