strcpy problem overlapping source and destination in 64 bit ( sun_solaris_x64 )
A simple program like the following when compiled for 64 bit, it gives wrong result in some of the 64bit m/c.
/* a.c */
#include <stdio.h>
#include <string.h>
int main()
{
char st[50];
char *p = st + 2;
strcpy(st,"XY1234");
strcpy(st,p);
printf("\n%s\n",st);
return 0;
}
cc -o check_copy -m64 a.c
On running check_copy, the expected answer is "1234", but in some m/c this gives "1434" .
The libc.so.1 in both the m/cs are different.
The result is correct in older SunOS.
uname -a in two m/cs ( old_mc and new_mc )
SunOS old_mc 5.10 Generic_127112-05 i86pc i386 i86pc [ Gives correct result ]
/* a.c */
#include <stdio.h>
#include <string.h>
int main()
{
char st[50];
char *p = st + 2;
strcpy(st,"XY1234");
strcpy(st,p);
printf("\n%s\n",st);
return 0;
}
cc -o check_copy -m64 a.c
On running check_copy, the expected answer is "1234", but in some m/c this gives "1434" .
The libc.so.1 in both the m/cs are different.
The result is correct in older SunOS.
uname -a in two m/cs ( old_mc and new_mc )
SunOS old_mc 5.10 Generic_127112-05 i86pc i386 i86pc [ Gives correct result ]
0