[comp.lang.c++] turbo C++/malloc probelm

larry@vaxb.acs.unt.edu (08/24/90)

I am using turbo c++ to write a game and I have run in to the following
problem.  I noticed that the values of one of the arrays I am using in my
program were wrong for no obvious reason.  Using the debugger, I stepped
through the program, and found that the changes occured during a malloc.

The code looks something like this.

.
 [code omited]
.
int segarr[11][7];
.
.
.
void *p0;
void *p1;
void *p2;
unsigned int size;
.
.
.
size = imagesize(0,0,20,20);
p0 = malloc(size);

the segarr values change as soon as the malloc executes.  After close
inspection with the debugger, I noticed that the address of p0 was inside
segarr.  The problem is obvious, the solution is not.  Oh, one other thing, the
pointers p0,p1, and p2, are part of a class.

Later........Larry

================================================================================
Larry Michalewicz             Bitnet : LARRY@UNTVAX 
VAX Operator/Programmer       THENET : NTVAXA::LARRY
(and student of CSCI at)    Internet : LARRY@VAXB.ACS.UNT.EDU
The University of North Texas   SPAN : UTSPAN::UTADNX::NTVAXA::LARRY
================================================================================

brown@cs.utk.edu (Lance A. Brown) (08/25/90)

I have also experienced this problem, but it happened to me while
using the TC++ compiler in "Pure C" mode.  I was not using any 
C++ code at the time.

I traced through the malloc code using Turbo Debugger and found that
the value of the BX register was not being restored properly at one
point.  This lead the program into putting the information for the 
pointed at data structure in the wrong place.

It is my feeling that this is NOT a C++ specific bug in the TC++
compiler, and may instead be a bug in the malloc code, or in the
compiler in GENERAL.

I am planning on verifying this is happening and then talking to the
Borland people.


Lance A. Brown