Bugzilla will be upgraded to version 5.0 on a still to be determined date in the near future. The original upgrade date has been delayed.
Bug 60388 - strlen() builtin bug
strlen() builtin bug
Product: Red Hat Raw Hide
Classification: Retired
Component: gcc3 (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Depends On:
  Show dependency treegraph
Reported: 2002-02-27 01:46 EST by Need Real Name
Modified: 2008-05-01 11:38 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2002-02-27 01:46:54 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Need Real Name 2002-02-27 01:46:50 EST
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

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:

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.
Comment 1 Jakub Jelinek 2002-03-04 09:36:14 EST
This was fixed by http://gcc.gnu.org/ml/gcc-patches/2002-01/msg00436.html

Note You need to log in before you can comment on or make changes to this bug.