mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2024-06-09 01:29:33 +00:00
Fix bug in initialization of auto arrays of strings.
When initializing (e.g.) an array of arrays of char, a string literal would be taken as an initializer for the outer array rather than for an inner array, so not all elements would be initialized properly. This was a bug introduced in commit 222c34a385
.
This bug affected the C4.6.4.2.CC test case, and the following reduced version:
#include <stdio.h>
#include <string.h>
int main (void) {
char ch2[][20] = {"for all good people", "to come to the aid "};
if (strcmp(ch2[1], "to come to the aid "))
puts("Failed");
}
This commit is contained in:
parent
3997fc6dce
commit
1fb1762458
61
Parser.pas
61
Parser.pas
|
@ -4423,37 +4423,38 @@ var
|
||||||
arrayType: begin
|
arrayType: begin
|
||||||
elements := itype^.elements;
|
elements := itype^.elements;
|
||||||
if elements = 0 then goto 1; {don't init flexible array member}
|
if elements = 0 then goto 1; {don't init flexible array member}
|
||||||
if iPtr^.iTree^.token.kind = stringConst then begin
|
if itype^.aType^.kind = scalarType then
|
||||||
elements := elements * itype^.aType^.size;
|
if iPtr^.iTree^.token.kind = stringConst then begin
|
||||||
size := iPtr^.iTree^.token.sval^.length;
|
elements := elements * itype^.aType^.size;
|
||||||
if size >= elements then
|
size := iPtr^.iTree^.token.sval^.length;
|
||||||
size := ord(elements)
|
if size >= elements then
|
||||||
else
|
size := ord(elements)
|
||||||
size := size-1;
|
else
|
||||||
if size <> 0 then begin
|
size := size-1;
|
||||||
GenLdcLong(size);
|
if size <> 0 then begin
|
||||||
Gen0t(pc_stk, cgULong);
|
GenLdcLong(size);
|
||||||
GenS(pc_lca, iPtr^.iTree^.token.sval);
|
Gen0t(pc_stk, cgULong);
|
||||||
Gen0t(pc_stk, cgULong);
|
GenS(pc_lca, iPtr^.iTree^.token.sval);
|
||||||
Gen0t(pc_bno, cgULong);
|
Gen0t(pc_stk, cgULong);
|
||||||
LoadAddress;
|
Gen0t(pc_bno, cgULong);
|
||||||
Gen0t(pc_stk, cgULong);
|
LoadAddress;
|
||||||
Gen0t(pc_bno, cgULong);
|
Gen0t(pc_stk, cgULong);
|
||||||
Gen1tName(pc_cup, 0, cgVoid, @'memcpy');
|
Gen0t(pc_bno, cgULong);
|
||||||
|
Gen1tName(pc_cup, 0, cgVoid, @'memcpy');
|
||||||
|
end; {if}
|
||||||
|
if size < elements then begin
|
||||||
|
elements := elements - size;
|
||||||
|
disp := disp + size;
|
||||||
|
LoadAddress;
|
||||||
|
Gen0t(pc_stk, cgULong);
|
||||||
|
Gen1t(pc_ldc, ord(elements), cgWord);
|
||||||
|
Gen0t(pc_stk, cgWord);
|
||||||
|
Gen0t(pc_bno, cgULong);
|
||||||
|
Gen1tName(pc_cup, -1, cgVoid, @'~ZERO');
|
||||||
|
end; {if}
|
||||||
|
iPtr := iPtr^.next;
|
||||||
|
goto 1;
|
||||||
end; {if}
|
end; {if}
|
||||||
if size < elements then begin
|
|
||||||
elements := elements - size;
|
|
||||||
disp := disp + size;
|
|
||||||
LoadAddress;
|
|
||||||
Gen0t(pc_stk, cgULong);
|
|
||||||
Gen1t(pc_ldc, ord(elements), cgWord);
|
|
||||||
Gen0t(pc_stk, cgWord);
|
|
||||||
Gen0t(pc_bno, cgULong);
|
|
||||||
Gen1tName(pc_cup, -1, cgVoid, @'~ZERO');
|
|
||||||
end; {if}
|
|
||||||
iPtr := iPtr^.next;
|
|
||||||
goto 1;
|
|
||||||
end; {if}
|
|
||||||
itype := itype^.atype;
|
itype := itype^.atype;
|
||||||
if ZeroFill(elements, itype, count, iPtr) then begin
|
if ZeroFill(elements, itype, count, iPtr) then begin
|
||||||
if itype^.kind = enumType then
|
if itype^.kind = enumType then
|
||||||
|
|
Loading…
Reference in New Issue
Block a user