🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #6121

Why is this possible?

#6121
From: Volker Luckas
Date: Thu, 05 Dec 1996 00:00
36 lines
1543 bytes
Hello all,

it was very astonishing for me to recognize that the following piece of
source code is accepted by gcc 2.7.2 (Solaris 2.5) without giving a
warning if gcc is called in the following way: 

gcc test.c -o test

#include <string.h>

int main( )
{
  char* str = "0.12345678";
  double val = 1.11111111;

  sprintf( str, "%lf", val );

  printf( "Result: %s\n", str );

  return 0;
}

The generated binary crashes if started afterwards. Interestingly this
does not happen if you compile the source with cc from the Solaris 2.5
Compiler package or even with gcc 2.7.2 running under IRIX 5.3

Compiling the source with -Wall gives you a warning about implicitely
defined functions but no warning about the illegal sprintf( ) call.

Is there any possibility to avoid this kind of behaviour ???

--
       (o o)
---ooO--(_)--Ooo---
Greetings Volker (luckas@igd.fhg.de)
Technical Details
Message-ID: <32A687B4.430F@igd.fhg.de>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113d02,8c9ed5628eb65d44,start
X-Google-Attributes: gid113d02,public
From: luckas@igd.fhg.de (Volker Luckas)
Subject: Why is this possible?
Date: 1996/12/05
Message-ID: <32A687B4.430F@igd.fhg.de>
X-Deja-AN: 202465634
sender: bug-gcc-request@prep.ai.mit.edu
content-type: text/plain; charset=us-ascii
organization: Organization: Haus der Graphischen Datenverarbeitung, 64283 Darmstadt
x-gateway: relay6.UU.NET from bug-gcc to gnu.gcc.bug; Thu, 5 Dec 1996 03:29:43 EST
mime-version: 1.0
newsgroups: gnu.gcc.bug
x-mailer: Mozilla 3.01Gold (X11; I; SunOS 5.5 sun4m)