Why does strcpy() not working as expected i.e. overlap on Red Hat Enterprise Linux 6 x86_64 ?
Issue
strcpy()
does not work as expected on Red Hat Enterprise Linux 6 x86_64- Here is an example:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
unsigned char s[200] = "1234567890";
main()
{
printf("\nOrig:%s\n",s);
strcpy(s,s+1);
printf("\nAfter:%s\n",s);
}
[root@zzz ~]# gcc test.c
[root@zzz ~]# ./a.out
Orig: 1234567890
After: 234567990
- This happens only on Red Hat Enterprise Linux 6 x86_64 and Fedora 16 x86_64, can not be reproduced on Red Hat Enterprise Linux 5 i386/x86_64 or Red Hat Enterprise Linux 6 i386 or 7 as well.
Environment
- Red Hat Enterprise Linux 6 x86_64
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.