#6705 segmentation fault (invalid code) in CheckVaarg::va_list_usage. Local fix i nchecker preventing SIGSEGV on NULL-token

This commit is contained in:
Alexander Mai 2015-05-27 21:12:33 +02:00
parent 0bd7cbfbeb
commit e498f8493e
2 changed files with 6 additions and 1 deletions

View File

@ -92,7 +92,7 @@ void CheckVaarg::va_list_usage()
bool exitOnEndOfStatement = false;
const Token* tok = var->nameToken()->next();
for (; tok != var->scope()->classEnd; tok = tok->next()) {
for (; tok && tok != var->scope()->classEnd; tok = tok->next()) {
if (Token::Match(tok, "va_start ( %varid%", var->declarationId())) {
if (open)
va_start_subsequentCallsError(tok, var->name());

View File

@ -84,6 +84,7 @@ private:
TEST_CASE(garbageCode43); // #6703
TEST_CASE(garbageCode44); // #6704
TEST_CASE(garbageCode45); // #6608
TEST_CASE(garbageCode46); // #6705
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
@ -485,6 +486,10 @@ private:
checkCode("struct true template < > { = } > struct Types \"s\" ; static_assert < int > ;");
}
void garbageCode46() { // #6705
checkCode(" { bar(char *x); void foo (int ...) { struct } va_list ap; va_start(ap, size); va_arg(ap, (d)); }");
}
void garbageValueFlow() {
// #6089
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"