CheckBufferOverrun: Skip warnings about array index out of bounds in unions. Theoretically, the array is at least as large as the biggest union member.

This commit is contained in:
Daniel Marjamäki 2016-12-18 22:10:30 +01:00
parent 4558701c08
commit f5ad7482a8
2 changed files with 9 additions and 0 deletions

View File

@ -1507,6 +1507,9 @@ void CheckBufferOverrun::bufferOverrun()
if (var->dimension(0) <= 1 && Token::simpleMatch(var->nameToken()->linkAt(1),"] ; }"))
continue;
if (var->scope() && var->scope()->type == Scope::eUnion)
continue;
ArrayInfo arrayInfo(var, symbolDatabase);
arrayInfo.varname(varname);

View File

@ -563,6 +563,12 @@ private:
" ab->a[0] = 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("union { char a[1]; int b; } ab;\n"
"void f() {\n"
" ab.a[2] = 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
}