Re: Memory problems... in _doprnt()!?! (fwd)

From: Billy H. Chan (~{3B:FH;~}) (bhchan@csua.berkeley.edu)
Date: 10/17/95


Thanks for all the helps and hints, esp. the course on gdb's bt and fr
commands.  I'm happy to say that I found the memory problem.  I don't 
know if I was just unlucky or silly, but in case someone else run into
the same thing later on, this is one thing to look for:

In my code, I had a statement like:
	sprintf(buf, "This is the first statement,");
	sprintf(buf, " %s <STUFF STUFF STUFF>\r\n", buf);

That extra space was the culprit, and I think the reasoning goes as
thus:
Compiler: sets buf one character at a time, sees the space and puts
it into buf, then sees the %s and puts another space in the buf or 
worst, a NULL... at this point, doprnt() crashes quite happily.

I solved it by setting the first statement to sprintf to buf2 instead
and incorporate buf2 into buf1 in the second sprintf.  So far, no
crashes. 

An interesting thing I did:  When I added 2 long ints for AFFs and PREFs
and MOB_flags and PLR_Flags, I had to reorganize the mob files.  Then, I
realized I had to modify alll the mob files.  After some thinking, and
because I wasn't good with sed/awk, I decided to make the db.c backwards
compatible and put an extra sscanf check to switch between "old style"
and "new style".  I highly recommend doing this because then, you can
load up someone else's area and later medit/iedit/redit things back to
"new style" (I made my iedit/redit save in "new style"... no medit yet...
sigh)
Anyway, just thought I'd share some of my own experience hacking CIRCLE.
-Billy H. Chan	~{3B:FH;~}		    <bhchan@csua.berkeley.edu> 
 For more, check out http://www.csua.berkeley.edu/~bhchan
 NovaCmdr. 'Suicide Strom' of Clan Wolf | FiestyFly FireMoth Variant
 "If you're going under 100kph, you might as well stand still"



This archive was generated by hypermail 2b30 : 12/07/00 PST