0 Replies Latest reply: Mar 25, 2013 1:04 AM by 998880 RSS

    strcpy problem overlapping source and destination in 64 bit.

    998880
      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 ]
      SunOS new_mc 5.10 Generic_147441-01 i86pc i386 i86pc [ Gives wrong result ]

      Both the m/c s have 118855-36 patch, which I believe is for libc.so.1.

      As our s/w is large one, it will be difficult to have a code fix, as there will be many instances of the above scenario and which triggered in very rare usecases.

      Any help, regarding the patch details which can fix this issue..