TIP: Click on subject to list as thread! ANSI
echo: cis.os9.68000.osk
to: All
from: Bob van der Poel 76510,2203
date: 1993-12-23 19:55:39
subject: C problems

#: 19522 S12/OS9/68000 (OSK)
    23-Dec-93  19:55:39
Sb: C problems
Fm: Bob van der Poel 76510,2203
To: All

I think I may have found a bug in the 2.3 C realloc() function. What appears to
happen is:

If realloc() fails (ie. returns a NULL ptr) it appears that the original memory
passed is freed! I have some code which looks something like this:

   newbuf=realloc(bufstart, memreq);
   if(!newbuf) ... report no more room error and restart....
   if(newbuf!=bufstart) ...set 'bufstart' etc to newbuf values if buffer moved

However, using SSM any access to memory in the original buffer generates a bus
error. I have verified this with srcdbg.

I have avoided the problem by not using realloc(). Instead I always allocate a
completely new buffer and then copy the old buffer to the new one and free()
the old one. This works...but is wasteful if the original could have been
expanded as realloc() does.

Anyone else had a similar problem?

SOURCE: compuserve via textfiles.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.