Bug 187540 - Using any explicit optimization level results in an executable that fails with 'segmentation fault.'
Using any explicit optimization level results in an executable that fails wit...
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: gcc4 (Show other bugs)
4
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2006-03-31 14:56 EST by John Slayton
Modified: 2007-11-30 17:11 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2006-04-03 08:26:47 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
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 (93.79 KB, application/x-bzip)
2006-03-31 14:56 EST, John Slayton
no flags Details

  None (edit)
Description John Slayton 2006-03-31 14:56:34 EST
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 14:56:35 EST
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 08:26:47 EDT
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.

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