Bug in Microsoft C Compiler in SCO Unix
Michael Landers
mykel at saleven.oz
Wed Jul 18 17:03:53 AEST 1990
The following correct code dumps core on under SCO (PC-DOS :-) Unix V3.2 with
the Microsoft C Compiler, as supplied, with default options.
main()
{
char foo[4];
goo(foo);
}
goo(foo)
char foo[];
{
foo[0] = foo[1] = foo[2] = '\0';
}
The problem is that the assembly code looks a bit like this...
_goo PROC NEAR
[ push registers ]
; Line 10
; foo = 8
; Line 11
mov eax, DWORD PTR [ebp+8]
mov ecx, DWORD PTR [ebp+8]
mov edx, DWORD PTR [ebp+8]
mov dh, 0
mov BYTE PTR [edx+2], dh
mov BYTE PTR [ecx+1], dh
mov BYTE PTR [eax], dh
; Line 12
[ pop registers, exit... ]
You will note that having set register `edx' to `foo' it then sets `dh'
to zero. This clobbers the value in `edx'. With no suprise, the code
then dumps core after trying to write into *edx.
I could write a better compiler with a spear through my head :-)
Mykel.
--
() \\ Black Wind always follows
|\/|ykel Landers (mykel at saleven.oz) \\ Where by dark horse rides,
_||_ \\ Fire is in my soul,
Phone: +612 906 3833 Fax: +612 906 2537 \\ Steel is by my side.
More information about the Comp.unix.i386
mailing list