www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/05/08/23:22:14

Date: Mon, 08 May 1995 21:11:15 -0500 (CDT)
From: Aaron Ucko <UCKO AT VAX1 DOT ROCKHURST DOT EDU>
Subject: Re: exception 14 runtime error
To: sjagordo AT FLASH DOT LakeheadU DOT CA
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Organization: Rockhurst College; Kansas City, MO

>My modified version compiles with Borland C++ (version 4.5) and with
>djgpp (from the archive gcc263bn.zip), but the djgpp version always
>crashes at runtime with the message:
>
>	 Segmentation violation in pointer 0x00000000 at ...
>
>Using "go32 -d edebug32", I get the message:
>
>	exception 14 (0xe) occurred, error code=0
>
>I have traced this in at least two cases.  The first occurs when the 
>string argument to atof() is NULL.  The second occurs when a NULL pointer 
>is dereferenced.  (Ultimately, these two errors are the same, since atof()
>attempts to dereference the NULL argument to read the string).
>
>When compiled with the Borland compiler, the program just runs right
>through these sections.  In fact, atof((char *) NULL) returns 0.0
>when compiled with Borland C++ 4.5.
>
>Is there any way to configure djgpp to ignore this exception?  As I said,
>the original version compiled under djgpp (I'm not sure which version of
>gcc, but at least 2.5.x or earlier).  My modifications to the program 
>have been limited to different source files--not the code where these 
>exceptions are occuring.

This is a feature, not a bug.  The result obtained by dereferencing a
null pointer is officially undefined by ANSI, so it is poor practice to
perform such dereferences in the assumption that you'll get any particular
value.  GCC automatically traps these dereferences to make you write more
valid code.

Solution:  Prevent null pointers from being dereferenced.  You can write a
simple wrapper for atof() and handle other situations equally appropriately.

--- Aaron Ucko (ucko AT vax1 DOT rockhurst DOT edu; finger for PGP public key) | httyp!
Geek code 2.1 [for explanation, finger hayden@ | `God's Laws' (Rudy Rucker,  
vax1.mankato.msus.edu]: GCS/M/S d(-) H s g+ p? \ _Master of Space and Time_):
!au a17 w+ v+(++) C++(+++)>++++ UL++(S+)>++++	\ 1) Be clean. 2) Follow Gary.
P+(++) L++ 3(-) E- N+(++) K- W--(---) M-@ V-(--) \ 3) Teach God's Laws.
po-(--) Y+ t(+) !5 j(++) R(-) G' tv--(-) b+++	  +---------------------------
!D(--) B--(---) e>++++(*) u++(@) h!() f(+) r-(--)>+++ n+(-) y?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019