delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/26/21:17:08

From: Mike Rusch <ruschtmm AT newnorth DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: keyword "new" causes SIGSEV
Date: Wed, 26 Aug 1998 20:06:03 -0500
Organization: CentWis Computing
Lines: 85
Message-ID: <35E4B0FB.D8D8AABC@newnorth.net>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 980825152707 DOT 7520j-100000 AT is>
Reply-To: ruschtmm AT newnorth DOT net
NNTP-Posting-Host: ribl1-cs-3.newnorth.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Here's what I've done.
First, I tried changing the effstrcpy function to this:

char *effstrcpy(char * &dest, const char *src) {
    int slen = strlen(src) + 1;
// ---THE NEXT LINE IS LINE 71---
    malloc(sizeof(char) * slen];
    return NULL;
}

I still got a SIGSEV on the malloc line.  The entire output screen is
below:

                                        What is your choice?
01234567Exiting due
 to signal SIGSEGV
General Protection Fault at eip=0000c1d8
eax=0000001c ebx=00000002 ecx=fffffffc edx=07200720 esi=00000018
edi=00058cc8
ebp=00058c58 esp=00058c50 program=C:\DJGPP\MIKE\COLLEGES.EXE
cs: sel=00af  base=83176000  limit=0006ffff
ds: sel=00b7  base=83176000  limit=0006ffff
es: sel=00b7  base=83176000  limit=0006ffff
fs: sel=0087  base=0000e030  limit=0000ffff
gs: sel=00c7  base=00000000  limit=ffffffff
ss: sel=00b7  base=83176000  limit=0006ffff

Call frame traceback EIPs:
  0x0000c1d8   _malloc+192
  0x0000726e   _effstrcpy__FRPcPCc+26, line 71 of effio.cpp
  0x00004e9a   _reptfmtcpy__FR7reptfmtG7reptfmt+254, line 1295 of
collegdb.cpp
  0x00006b13   _formatnew__Fv+75, line 1806 of collegdb.cpp
  0x000069c1   _format__Fv+421, line 1763 of collegdb.cpp
  0x00008082   _Show__7MenuBari+1094, line 328 of menusys.cpp
  0x00001723   _main+387, line 95 of collegdb.cpp
  0x0000ac62   ___crt1_startup+138

C:\DjGPP\MIKE>symify colleges.exe

C:\DjGPP\MIKE>

The 01234567 after "What is your choice?" was generated by debugging
code I inserted just before the call to effstrcpy.  It shows that on the
7th call the error occurred (just like before).

Now, I also tried changing malloc to xmalloc, calloc, and alloca.  The
former two just call malloc, and I got the same error.  However, when I
used alloca, everything worked fine.  I'm afraid that was just luck,
though, since the memory is deallocated at the end of the function when
alloca is used, and I need to use that memory after the function ends.

Maybe my computer can't deal with 7s except at midnight when there's a
lunar eclipse :).  Barring this, are there any more suggestions???

Mike.

BTW, I was surprised to get three responses in just two days.  You guys
are really good!

Eli Zaretskii wrote:
> 
> On Mon, 24 Aug 1998, Mike Rusch wrote:
> 
> > When I run the program and get to a point where reptfmtcpy is used (in
> > function formatnew(), I get a SIGSEV:
> >
> >   0x0000c8d0   _malloc+192
> 
> First, please never censor the traceback that is printed at the point
> of crash; always post it in its entirety.  The part that you omitted
> (the register dump, selectors, etc.) includes important information
> that tells a lot to those who know how to read it.
> 
> And second, crashes at _malloc+192 usually mean that some part of your
> program writes past the end of an allocated buffer, like if you
> allocate 20-byte buffer and copy a 20-character string into it.  I
> suggest to look for such code in your program.
> 
> > From the traceback it almost looks like "new" calls
> > malloc, but this seems strange to me since new is supposed to be a
> > keyword, and supposedly more efficient than malloc.
> 
> `new' calls `malloc' internally.  But I don't think the problem is
> with `malloc', most probably your code is doing something bad.

- Raw text -


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