Article View: gnu.g++.bug
Article #840Re: executable crash under g++/Sun
From: Mike Stump
Date: Sat, 29 Aug 1992 16:22
Date: Sat, 29 Aug 1992 16:22
68 lines
1987 bytes
1987 bytes
It is not valid in ANSI C++ to modify strings ("..."). Your program does.
> Message-Id: <9208261811.AA11644@poincare.phys.cmu.edu>
> To: bug-g++@prep.ai.mit.edu
> Cc: keister@poincare.phys.cmu.edu, lambert@mamba.psc.edu
> Date: Wed, 26 Aug 92 14:11:38 -0400
> From: "Bradley D. Keister" <keister@poincare.phys.cmu.edu>
> The following code crashes at runtime when built with g++/Sun. It
> runs without trouble under g++/DECstation and CC/DECstation.
> #include <stdio.h>
> #include <string.h>
> // #include "strup.h"
> void strup(char* string)
> {
> for (; *string; string++)
> *string = ((*string >= 'a') && (*string <= 'z'))?
> *string-0x20: *string;
> }
> class A {
>
> protected:
> int a;
>
> public:
> A() {a=1;}
> };
> class B : public A {
>
> protected:
> int b;
>
> public:
> B() {b=1;}
> };
> A* choose_class(char* keyword)
> {
> A* result;
> strup(keyword);
> if (strcmp(keyword, "CLASS_A") == 0)
> result = new A;
> if (strcmp(keyword, "CLASS_B") == 0)
> result = new B;
>
> return result;
> }
> main()
> {
> A* Atest = choose_class("class_B");
> delete Atest;
> return 0;
> }
> Segmentation fault (core dumped)
> cm5comp.psc.edu% dbx declare
> Reading symbolic information...
> Read 194 symbols
> program terminated by signal SEGV (access to address exceeded protections)
> (dbx) run
> Running: declare
> signal SEGV (access to address exceeded protections) in strup__FPc at 0x22f8
> strup__FPc+0x68: stb %o1, [%o0]
Technical Details
Message-ID:
<9208291622.AA00394@cygnus.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!wupost!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cygnus.com!mrsShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cygnus.com!mrs From: mrs@cygnus.com (Mike Stump) Subject: Re: executable crash under g++/Sun Message-ID: <9208291622.AA00394@cygnus.com> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Sat, 29 Aug 1992 16:22:17 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 69