Bug 60388 - strlen() builtin bug
Summary: strlen() builtin bug
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Raw Hide
Classification: Retired
Component: gcc3
Version: 1.0
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-02-27 06:46 UTC by Need Real Name
Modified: 2008-05-01 15:38 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2002-02-27 06:46:54 UTC
Embargoed:


Attachments (Terms of Use)

Description Need Real Name 2002-02-27 06:46:50 UTC
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.

Comment 1 Jakub Jelinek 2002-03-04 14:36:14 UTC
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.