Thanks! I corrected that bug, hopefully avoiding a future crash.
After your help with gdb, I was able to set some breakpoints and step through the code, and I'm confident I've found the function that is causing the problem.
In ictime.cpp, the function get_ictimediff() is called from show_score(), which is called from do_score().
This function is also called from do_rpsheet(), and when I type that command, the mud crashes in exactly the same way.
Here is the code for that function. From what I can understand, this function returns a string containing the age of the character in years, days, months and seconds, taking into account the current amount of time played and the starting age of a character (17 years).
It's been a -long- time, Nick, since I studied C++, and in my current vocation, I have no need for it at all, so my memory is fuzzy on the algorithm for deriving time from a number of seconds...but if I'm reading this right, the %= operator is used to distil the age of the character in seconds ( abs((int)(t1-t2)) ) down to years, days, months and seconds.
What I don't understand is the line:
++index%=3;
What is the purpose of this? I did a 'print index' prior to this line, which indicated 0, and afterward it contained 1.
Why not just index=1;? It's a local integer used in an array later...
Anyway the line where the mud crashes is the sprintf statement. I'm really fuzzy on multidimensional array syntax these days, but it seems strange to me how timebuf[] is created and used in this function.
Here is the function in question:
char *get_ictimediff(time_t t1, time_t t2, int icyears_added_to_result)
{
static char timebuf[MSL][3];
static int index;
int dsec, icyear, icmonth, icweek, icday;
++index%=3;
// initialise working string
timebuf[index][0]=0;
dsec = abs((int)(t1-t2)); // number of IRL seconds between the 2 times
icyear = dsec/ICTIME_IRLSECS_PER_YEAR;
icyear+= icyears_added_to_result;
dsec %= ICTIME_IRLSECS_PER_YEAR;
icmonth= dsec/ICTIME_IRLSECS_PER_MONTH;
dsec %= ICTIME_IRLSECS_PER_MONTH;
icweek = dsec/ICTIME_IRLSECS_PER_WEEK;
dsec %= ICTIME_IRLSECS_PER_WEEK;
icday = dsec/ICTIME_IRLSECS_PER_DAY;
sprintf(timebuf[index],"%d year%s, %d month%s, %d week%s, %d day%s",
icyear,
(icyear!=1?"s":""),
icmonth,
(icmonth!=1?"s":""),
icweek,
(icweek!=1?"s":""),
icday,
(icday!=1?"s":""));
return(timebuf[index]);
}
Thanks again for your time, Nick. I promise to dust off those old C and C++ books and make you proud one day....
S |