[comp.lang.c] This can't be a TurboC bug can it?

CRN@BYUVM.BITNET (07/31/90)

I am having a VERY weird problem in TurboC.  My code looks
something like this:


typedef struct{
   . . .
   char   *str;
int    type;
}FIELD;


int proc(FIELD *fld)
{
   . . .
   if(!valid_str(fld->str))
      return ERROR;
   . . .
}

Here's the weird part.  Using Turbo Debugger I have found that my
program crashes right after this statement.  I perform a watch on
fld, fld->str, fld->type.  Before the call to valid_str() all of the
variables are fine.  Upon return from valid_str(), however, the
pointer, fld, is screwed up which of course in turn screws up
fld->str and fld->type.   I assume that fld is being overwritten
somehow but I can't figure out how.  Valid_str() does nothing to
manipulate fld and the only function that valid_str() calls is
atoi() (yes, I do include stdlib.h).  If anyone has any pointers
for me I'd sure appreciate hearing them.

-- Cory
(crn@byuvm.bitnet)

brianr@hpdmd48.boi.hp.com (Brian Rodriguez) (08/15/90)

/ hpdmd48:comp.lang.c / CRN@BYUVM.BITNET / 10:35 am  Jul 31, 1990 /

	I once had a similarly mysterious experience with TurboC.  Are you
using any static or global arrays inside valid_str()?  If so, you may be
writing past the array bounds, and if by chance fld is stored immediately
after the array, it will be overwritten during the valid_str() call.  If
the situation I have described does not exist, I wish you luck.

--- Brian Rodriguez
(brianr@hpbs1526.boi.hp.com)