Hi, when compiling the appended C-code first with gcc -v -save-temps bug.c and then with gcc -v -save-temps -O bug.c you will see garbage at the end of the output of the optimized case. Best regards Willi N|_er, LinuxLab SAP AG ********************************************* ****** bug.c ******************************** ********************************************* #include <stdio.h> #include <stdlib.h> /*#define TRAILER 0x07*/ #define TRAILER 'A' static char buf[40]; static char line[30] = "1234567890123456789012345678*"; static void f() { char trailer[2] = { TRAILER, 0x00 }; char* const last = buf + sizeof(line) - 2; memcpy(buf, line, sizeof(line)); if (*last == '*') { memcpy(last, trailer, 2); } } int main() { f(); printf("%s\n", buf); return 0; } ************************************************** ****** end of bug.c ****************************** **************************************************
I have sent a fix for this to the GCC gurus at: http://egcs.cygnus.com/ml/gcc-patches/1999-09/msg01103.html We will see what they say.
The update is at: http://egcs.cygnus.com/ml/gcc-patches/1999-09/msg01170.html
That patch may be a good choice. See: http://egcs.cygnus.com/ml/gcc-patches/1999-09/msg01240.html
Created attachment 37 [details] Slightly more elaborate strict_low_part patch
Fixed in the egcs currently in Raw Hide.