This bug is in all versions of gcc I tested:  3.2.3, 3.3.4, and 3.3.6.  I am
using Slackware Linux version 10.2 on a Pentium 4 based PC, and the gcc it came
with, version 3.3.6.  When the following program is compiled without
optimization, it runs correctly.  When compiled with any optimization, the
second call to scanf incorrectly overwrites the short int "u".  Maybe this bug
is the same as bug 15484.


A program that causes the bug:

#include <stdio.h>
int  main() {
  short int  l, u;

  puts("upper?");
  scanf("%d", &u);
  puts("lower?");
  scanf("%d", &l);

  printf("\n%d %d\n", l, u);
  return 0;
}


The commands I used to compile the above program:  (bash shell)

g++ -g -o gcc_bug gcc_bug.cc 
g++ -g -O2 -o gcc_bug gcc_bug.cc 


The compiler gives no messages when compiling this program.


-- 
           Summary: short int parameter wrong in optimized code
           Product: gcc
           Version: 3.3.6
            Status: UNCONFIRMED
          Severity: major
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: chapinb at acm dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24506

Reply via email to