Bug 187540

Summary: Using any explicit optimization level results in an executable that fails with 'segmentation fault.'
Product: [Fedora] Fedora Reporter: John Slayton <juanslayton>
Component: gcc4Assignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 4   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-04-03 12:26:47 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Tarball will create directory 'bugstash' which contains source greader.c and data files needed to run the executable. Also included are two executables from my machine, with/without -O2 none

Description John Slayton 2006-03-31 19:56:34 UTC
Description of problem:
     Compiling source 'greader.c' with default optimization, program compiles
cleanly with no errors or warnings, and runs properly.  Trying to compile with
explicit optimization (as 'gcc -lncurses -O2 greader.c'), program still compiles
and exits cleanly with no errors or warnings.  However, resulting executable
fails on invocation with error message 'segmentation fault'.
     This happens when run on a Compaq Presario 5050 under Fedora
Core(2.6.11-1.1369_FC4), using gcc version 4.0.0 20050519 (Red Hat 4.0.0-8). 
This last according to 'gcc --version'; dmesg gives a slightly different 'gcc
version 4.0.0 20050525 (Red Hat 4.0.0-9)'.
     When run under Slackware 10 (Linux 2.4.26) with gcc version 3.3.4, this
code compiles and runs properly with or without explicit optimization settings.
     I didn't fit in everything below; just let me say that after unfolding the
attached tarball, you should be able to invoke the program with
'/bugstash/greader_default'.


Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1.
2.
3.
  
Actual results:


Expected results:


Additional info:

Comment 1 John Slayton 2006-03-31 19:56:35 UTC
Created attachment 127149 [details]
Tarball will create directory 'bugstash' which contains source greader.c and data files needed to run the executable.  Also included are two executables from my machine, with/without -O2

Comment 2 Jakub Jelinek 2006-04-03 12:26:47 UTC
That's just buggy testcase:
in download_roster, there is
char zo[2];
...
(not initialized in any way), then:
  for (a = 0;  a < Class_size; a++)
    {
      strcpy (Buf, "/tmp/bugstash/Name");
      zo[0] = (char)((a / 10) + 48);
      strcat (Buf, &zo[0]);
      zo[0] = (char) ((a % 10) + 48);
      strcat (Buf, &zo[0]);
      fp = fopen(Buf, "r");
      fgets (Name[a], 500, fp);
      fclose(fp);
    }

That triggers undefined behavior, can work only if zo[1] happens to have value 0,
but nothing initialized it that way.