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:
parent
4558701c08
commit
f5ad7482a8
|
@ -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);
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue