n62@np1.hep.nl (Klamer Schutte) (03/02/89)
I found a bug in the minix-st compiler ( could be also in the PC version;
i don't know ). The bug occurs when somebody tries to initialise a
structure containing items with an odd length. I don't know where the
bug occurs: cem, opt, cg? and i don't have source's of the compiler.
Here is the source causing the bug:
struct foo
{ char three[3];
char one;
} bar[4] = { { "te", 1 }, { "st", 2 } };
main()
{
int i;
for( i=0; i<3; i++)
{ printf("0 : %d 1 : %d 2 : %d 3 : %d 4 : %d\n",
bar[i].three[0], bar[i].three[1], bar[i].three[2],
bar[i].three[3], bar[i].three[4] );
printf("three : %s one : %d\n", bar[i].three, bar[i].one );
}
}
This gives the following assembly:
.sect .text;.sect .rom;.sect .data;.sect .bss
.extern _bar
.sect .data
_bar:
.data2 29797
.data2 0
.data2 371
.data2 29696
.data2 2
.data2 0
.data2 0
.data2 0
.extern _main
.data2 0
.sect .text
_main:
link a6,#-2
< following code deleted >
I think the code following _bar: should have been:
.data2 't'*256+'e'
.data2 0*256+1
.data2 's'*256+'t'
.data2 0*256+2
.data2 0
.data2 0
as the compiler thinks when accessing bar[] each item has size 4.
Here is the output of the program, piped through od:
a.out | od -chx > outputfile
0000000 3020 3a20 3131 3620 3120 3a20 3130 3120
0 : 1 1 6 1 : 1 0 1
0000010 3220 3a20 3020 3320 3a20 3020 3420 3a20
2 : 0 3 : 0 4 :
^^ should be 1
0000020 310a 7468 7265 6520 3a20 7465 206f 6e65
1 \n t h r e e : t e o n e
^^ should be 115 = 's'
0000030 203a 2030 0a30 203a 2031 2031 203a 2031
: 0 \n 0 : 1 1 : 1
0000040 3135 2032 203a 2031 3136 2033 203a 2030
1 5 2 : 1 1 6 3 : 0
0000050 2034 203a 2030 0a74 6872 6565 203a 2001
4 : 0 \n t h r e e : 001
0000060 7374 206f 6e65 203a 2030 0a30 203a 2030
s t o n e : 0 \n 0 : 0
0000070 2031 203a 2032 2032 203a 2030 2033 203a
1 : 2 2 : 0 3 :
0000080 2030 2034 203a 2030 0a74 6872 6565 203a
0 4 : 0 \n t h r e e :
0000090 2020 6f6e 6520 3a20 300a
o n e : 0 \n
000009A
Remedy: avoid initialising such struct's
Klamer
--
________________________________________________________________________________
Klamer Schutte mcvax!nikhefh!n62 n62@nikhefh.hep.nl