www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/20/16:16:32

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Why does this code crash?
Date: Mon, 20 Jul 1998 13:01:37 -0700
Organization: Alcyone Systems
Lines: 42
Message-ID: <35B3A221.5ED00CB1@alcyone.com>
References: <35B3391A DOT 227330DD AT earlham DOT edu>
NNTP-Posting-Host: charmaine.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Walter Luke wrote:
> 
>    I apologize if the problem I'm having is simple--I'm new to C. The
> following code generates a general protection fault and crashes the
> DOS window. The error message reads, among other things, "Exiting due
> to signal SIGSEGV". If someone could look over this and try to see
> where the error is, it would be a big help...

The error is that you're exceeding the bounds of the array:

max AT charmaine:~/tmp% gcc -ggdb gene.c -o gene
max AT charmaine:~/tmp% gdb ./gene
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for
details.
GDB 4.16 (i486-slackware-linux), 
Copyright 1996 Free Software Foundation, Inc...
(gdb) run
Starting program: /home/max/tmp/./gene 

Program received signal SIGSEGV, Segmentation fault.
0x804842f in main () at gene.c:52
52                        gene[genepool][7][1]=g;
(gdb) bt
#0  0x804842f in main () at gene.c:52
#1  0x80480ee in ___crt_dummy__ ()
(gdb) print genepool
$1 = 517
(gdb) quit
The program is running.  Quit anyway (and kill it)? (y or n) yes

gene is only declared to have 500 elements, and you're overwriting that
bound.

-- 
         Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com
                       Alcyone Systems / http://www.alcyone.com/max/
  San Jose, California, United States / icbm:+37.20.07/-121.53.38
                                     \
           I put away my nine, fool / 'cause I'm colorblind.
                                   / Ice Cube

- Raw text -


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