Do not attempt to generate code for malformed initializers with no usable initializer expression.

This would lead to null pointer dereferences, and could possibly cause unpredictable behavior based on the values read.
This commit is contained in:
Stephen Heumann 2019-12-23 14:09:08 -06:00
parent 7f79b49c3a
commit b0b2b3fa91

View File

@ -3826,7 +3826,7 @@ var
{ count - number of times to re-use the initializer } { count - number of times to re-use the initializer }
{ ip - pointer to the initializer record to use } { ip - pointer to the initializer record to use }
label 1; label 1,2;
var var
elements: longint; {# array elements} elements: longint; {# array elements}
@ -3900,9 +3900,11 @@ var
case itype^.kind of case itype^.kind of
scalarType,pointerType,enumType,functionType: begin scalarType,pointerType,enumType,functionType: begin
tree := iptr^.itree;
if tree = nil then goto 2; {don't generate code in error case}
LoadAddress; {load the destination address} LoadAddress; {load the destination address}
doDispose := count = 1; {generate the expression value} doDispose := count = 1; {generate the expression value}
tree := iptr^.itree; {see if this is a constant} {see if this is a constant}
{do assignment conversions} {do assignment conversions}
while tree^.token.kind = castoper do while tree^.token.kind = castoper do
tree := tree^.left; tree := tree^.left;
@ -3935,7 +3937,7 @@ var
pointerType,functionType: pointerType,functionType:
Gen0t(pc_sto, cgULong); Gen0t(pc_sto, cgULong);
end; {case} end; {case}
end; 2: end;
arrayType: begin arrayType: begin
if itype^.aType^.kind = scalarType then if itype^.aType^.kind = scalarType then