Fw: [techtalk] A SIGSEGV problem

Ellen Venable ev at cabrillo.cc.ca.us
Thu May 4 23:27:01 EST 2000


here's an example:

I made a program called test.cc:
------------------------------------------------
#include <iostream.h>

main(){
 char * ptr;
  while(1){
// we'll print out whatever ptr points to (garbage)
// and then we'll increment ptr to move to the
// next memory location to be sure we eventually
// get outside of the memory belonging to our program
    cout <<ptr++;
  }
}
------------------------------------------------------
now compile it

>g++ -ansi -Wall -g test.cc

(the -g flag is for the debugger)

now run it

>./a.out


Hcccc(eeeec
c
c

Segmentation fault
                        
now run the debugger

>gdb a.out

GNU gdb 4.18
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you
are
welcome to change it and/or 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.
This GDB was configured as "i386-suse-linux-gnu"...
(gdb) run
Starting program: /home/ev/a.out 

Hcccc(eeeec
c
c

Program received signal SIGSEGV, Segmentation fault.
0x400487c7 in ostream::operator<< (this=0x8049998, 
    s=0x804a000 <Address 0x804a000 out of bounds>) at iostream.cc:823
823     iostream.cc: No such file or directory.
(gdb) backtrace
#0  0x400487c7 in ostream::operator<< (this=0x8049998, 
    s=0x804a000 <Address 0x804a000 out of bounds>) at iostream.cc:823
#1  0x80487e1 in main () at test.cc:10
(gdb) quit
The program is running.  Exit anyway? (y or n) y
-----------------------------------------------

Under windows, this printed out stuff for quite a while and
then windows did notice that we went out of bounds
(got "Access Violation" error)







More information about the Techtalk mailing list