From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.8+) Gecko/20020212 Description of problem: The builtin strlen() produced a wrong value in the short test program I included below. Certain conditions had to be met to reproduce the bug: * the char pointer variable had to be of global scope * the variable had to be referred to before incrementing Upgrading Rawhide gcc RPMs from 3.1-0.11 to 3.1-0.21 has fixed the bug. However, I could not find a bug report on strlen() builtin in GNATS or RedHat Bugzilla. ============================================================== #include <string.h> #include <stdio.h> // Compile this with Rawhide RPMs pertaining to gcc-3.1-0.11: // gcc -O2 -o strlen strlen.c char *start; // Must be of global scope to trigger the bug int main() { char *s = "test"; start = s; // Must refer to "start" before incrementing to trigger the bug: printf("s \"%s\", len %d\n", s, start - s); start += strlen(s); printf("s \"%s\", len %d\n", s, start - s); return 0; } ============================================================== Version-Release number of selected component (if applicable): gcc-3.1-0.11 et al. How reproducible: Always Steps to Reproduce: $ gcc -O2 -o strlen strlen.c $ ./strlen Actual Results: s "test", len 0 s "test", len 5 Expected Results: s "test", len 0 s "test", len 4 Additional info: I submitted a similar report to GCC GNATS bug tracking system today.
This was fixed by http://gcc.gnu.org/ml/gcc-patches/2002-01/msg00436.html