🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #5982

Re: compiled code dumps core

#5982
From: Rainer Blome
Date: Sun, 19 Jan 1997 00:00
52 lines
2643 bytes
Dean S. Messing wrote:

> Here is a tiny piece of code to tickle the bug:
> 
>        int INF[]        = {0x7ff00000, 0x0};     /* IEEE infinity.  */
> 
>        main()
> 10       {
> 11         double f;
> 12         f = *(double *)INF;
> 13         printf("f = %lf\n", f);
> 14         return 0;
> 15       }

The int array is aligned to 4-Byte boundaries.  Working with doubles
requires alignment to 8-Byte boundaries (at least on Ultras), or so it
seems.  This is what the difference b/w a segmentation fault (you are
not allowed to access memory in that range) and a bus error (you are not
allowed to load data of this type from an address modulo 8 not equal to 
zero).

This is what I get for your test program (not the -Wpointer-arith flag):

make -k align;
gcc -pipe -g -Wall -W -Wwrite-strings -Wpointer-arith
-Wbad-function-cast -Wcast-align -Wstrict-prototypes
-Wmissing-prototypes -Wmissing-declarations -Wnested-externs
-Wconversion -Wsynth -Wtraditional -Winline -fno-dollars-in-identifiers
-Woverloaded-virtual  -o align align.c;
align.c:10: warning: return-type defaults to `int'
align.c:10: warning: function declaration isn't a prototype
align.c: In function `main':
align.c:12: warning: cast increases required alignment of target type
align.c:13: warning: use of `l' length character with `f' type character


> Furthermore each of the following versions work correctly
> with or without the "-traditional" flag.
> 
> [ code with pointers to double, not actual doubles ... ]

Here, nobody except printf accesses the memory of the array.
And printf probably reads the double byte-by-byte (or so), not as
a whole double value.  So it does not try a misaligned access.

Rainer

_________________________________________________________________________
   Rainer Blome			     http://www.physik3.gwdg.de/~rainer/
   Drittes Physikalisches Institut	
   Buergerstr.42, 37073 Goettingen, Germany	   Tel:(+49)551-39-77-31
Technical Details
Message-ID: <32E25378.67D1@physik3.gwdg.de>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <199701160258.SAA03305@cortex>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113d02,1b0cb93b1c507fb3
X-Google-Attributes: gid113d02,public
From: rainer@physik3.gwdg.de (Rainer Blome)
Subject: Re: compiled code dumps core
Date: 1997/01/19
Message-ID: <32E25378.67D1@physik3.gwdg.de>
X-Deja-AN: 210897557
sender: bug-gcc-request@prep.ai.mit.edu
references: <199701160258.SAA03305@cortex>
content-type: text/plain; charset=us-ascii
organization: III. Physik, University of Goettingen
x-gateway: relay2.UU.NET from bug-gcc to gnu.gcc.bug; Sun, 19 Jan 1997 15:29:22 EST
mime-version: 1.0
newsgroups: gnu.gcc.bug
x-mailer: Mozilla 3.01Gold (X11; I; SunOS 5.5 sun4m)