Wed 26 Jan 2005 08:31:14 PM UTC, original submission:
The following function:
typedef short bsdstuff_size_t;
PUBLIC char strncpy(char dst, const char *src, bsdstuff_size_t n)
{
// printf("src=%s\r\n", src);
// printf("size=%d", n);
if (n != 0) {
char *d = dst;
const char *s = src;
do {
if ((d++ = s++) == 0) {
/* NUL pad the remaining n-1 bytes */
while (--n != 0)
*d++ = 0;
break;
}
} while (--n != 0);
}
//printf("dst=%s\r\n", dst);
return (dst);
}
appears to be invalidly compiled with:
m6811-elf-gcc -g -DHI7 -DS12 -g -Os -mshort -m68hcs12 -mauto-incdec
-mlong-calls -msoft-reg-count=4
-L/usr/lib/gcc-lib/m6811-elf/3.0.4/m68hc12/ -fno-builtin -c -o
obj/S12/bsdstuff.elf bsdstuff.c
and the following sequence generated looks suspicious:
d4a69: fe 19 c7 ldx 19c7 <_.frame>
d4a6c: ed 00 ldy 0,X
reg.y = s
d4a6e: ee 02 ldx 2,X
reg.x = d
d4a70: 18 0a 70 00 movb 1,Y+, 0,X
reg.x = reg.y++
i.e. d = (s++) (except s++ not stored)
d4a74: 6d 00 sty 0,X
Wrong!
should be s = reg.y
but actually, is *d = reg.y
It's probably due to the "sty" that thinks register X
corresponds to the frame which does not look correct
at first glance.
|