[comp.os.msdos.programmer] Stack Overflow! tc++

pts@faraday.clas.Virginia.EDU (Paul T. Shannon) (03/06/91)

I have a turbo c++ bug that perhaps some one has seen before.  I suspect
that this is a bug in the compiler (borland's c++ version 1.0).

I've developed a small class that does ega animation by storing images in
expanded memory, and retrieving them on demand.  This code works great
when all of the source code is in one file.  All possible error checking
is on, at both compile- and run-time.   I've exercised this a lot. 
For simplicity, let's call this file class.cpp.

In preparation for using this class with a larger c++ program, I decided
to test the new class by calling it out of a very small separate main
program (call it main.cpp).  The class header is included, and maybe 40
lines of code were moved from class.cpp to main.cpp.   

Now I find that as soon as the first call is made  by main.cpp, to a member 
function in class.cpp, the program aborts with the message 

  Stack Overflow!

I've checked for errors, I've tried many different memory models, I've 
traced execution with td 2.0.  All to no avail.

If however, I turn the stack checking off (from the compiler option menu),
the program runs fine....except that I'm really nervous about what sins
might be hidden behind the curtains.

Has anyone seen a bug like this?  Any suggestions?

 - Paul Shannon
   pts@virginia.edu

6600m00n@ucsbuxa.ucsb.edu (Steelworker) (03/07/91)

In article <1991Mar6.135439.22464@murdoch.acc.Virginia.EDU> pts@faraday.clas.Virginia.EDU (Paul T. Shannon) writes:

[description deleted . . .]
:Now I find that as soon as the first call is made  by main.cpp, to a member 
:function in class.cpp, the program aborts with the message 

:  Stack Overflow!

:I've checked for errors, I've tried many different memory models, I've 
:traced execution with td 2.0.  All to no avail.

:If however, I turn the stack checking off (from the compiler option menu),
:the program runs fine....except that I'm really nervous about what sins
:might be hidden behind the curtains.

:Has anyone seen a bug like this?  Any suggestions?

: - Paul Shannon
:   pts@virginia.edu

This just means that you have allocated more than the default amount
of data available on the stack (4k?).  If you declare large arrays on the
stack, it can quickly fill up.  Also, if you pass large structures to
functions, that can use up a lot of your stack.   
The other possible problem ( does not seem to be your case) happens when
a user function is called from an interrupt ( often used in mouse
functions), and the stack is not in the state Turbo-c thinks it should
be in.  
In general, you should leave stack checking on; otherwise, your programs
will get untrackable bugs when you run out of stack.

Good luck,
Robert Blair

waynet@kit.tek.com (Wayne Turner) (03/07/91)

Subject: Re: Stack Overflow! tc++

In article <1991Mar6.135439.22464@murdoch.acc.Virginia.EDU> pts@faraday.clas.Virginia.EDU (Paul T. Shannon) writes:
>I have a turbo c++ bug that perhaps some one has seen before.  I suspect
>...
>If however, I turn the stack checking off (from the compiler option menu),
>the program runs fine....except that I'm really nervous about what sins
>might be hidden behind the curtains.
>
>Has anyone seen a bug like this?  Any suggestions?

Borland Tech Support admitted to me about 6 months ago that this was
a bug in their compiler. Do *not* use the stack overflow switch for
the compiler.  In tracing through disassembled code I discovered
that in some routines the prolog code that checks for stack overflow was
correct and in others it was wrong (instead of using _stklen for the
comparison it was using the address of a static object defined higher
up in the source module!!). This occurred in version 1.0 of TC++ and
I'm not sure if it was fixed in 1.01. I haven't seen anything in the
un-official 1.0 bug lists (posted on the net) to indicate that it was fixed.

I'm sure that many people have been hit by this bug and that much
development time has gone down the drain over it.

Borland, are you listening?

sidney@borland.com (Sidney Markowitz) (03/07/91)

In article <902@masterCNA.TEK.COM> waynet@kit.tek.com (Wayne Turner) writes:
>Subject: Re: Stack Overflow! tc++
>
>In article <1991Mar6.135439.22464@murdoch.acc.Virginia.EDU> pts@faraday.clas.Virginia.EDU (Paul T. Shannon) writes:
>>If however, I turn the stack checking off (from the compiler option menu),
>>the program runs fine....except that I'm really nervous about what sins
>>might be hidden behind the curtains.

The particular symptoms Paul describes are almost certainly really the
result of stack overflow, and the fix is to determine if he really
needs more stack space and if he does, then increase the size of the
stack over the default 4k.

>Borland Tech Support admitted to me about 6 months ago that this was
>a bug in their compiler. Do *not* use the stack overflow switch for
>the compiler.

The bug is in TC++ 1.00 in large and huge model. Compiling with stack
checking on can lead to linker errors and other randomness. It does
not usually lead to bogus stack overflow error messages, and it
doesn't happen in small model (I don't recall if it is in compact or
medium, but if it is in one it isn't in the other), so that is not the
cause of Paul's problem.

The bug is fixed in version 1.01, which is available by calling
Borland Customer Service at the 800 number that appears in their
magazine ads. I don't want to sound commercial on the net,
so I won't mention the $15 fee for shipping and materials, except to
say that some people have found that if they don't ask about it when
they call, *sometimes* the person taking the order forgets to ask for
it :-)

>Borland, are you listening?

 -- Sidney Markowitz <sidney@borland.com>
    Borland International (Languages R&D)
   [Note: I am not in Tech Support or Customer Service, and those
    departments are not yet hooked into our Internet connection.
    Any t.s. or c.s. type e-mail sent to me will be read with good
    intentions, but is subject to my forgetting about them when I get
    distracted by my next work crisis before I figure out who to pass
    it on to. The official channels will still work better.]

teexnma@ioe.lon.ac.uk (Nino Margetic) (03/07/91)

In <902@masterCNA.TEK.COM> waynet@kit.tek.com (Wayne Turner) writes:

[*** stuff deleted ***]

>                              This occurred in version 1.0 of TC++ and
>I'm not sure if it was fixed in 1.01. I haven't seen anything in the
>un-official 1.0 bug lists (posted on the net) to indicate that it was fixed.

***** Is this list available for ftp anywhere? Alternatively, is there
a kind soul around who would email it to me??

Thanks in advance.

--Nino

-- 
Janet: nino@uk.ac.ucl.sm.mph                    \    Nino Margetic
Earn/Bitnet: nino@mph.sm.ucl.ac.uk               \   Dept. of Medical Physics
Internet: nino%mph.sm.ucl.ac.uk@nsfnet-relay.ac.uk\  University College London
Bang-path: ....!mcvax!ukc!ucl-mph!nino             \ Tel:+44-71-380-9300/x5313