[crossfire] Found & maybe fixed bug in saving/loading level hp/sp/gp

Scott Kullberg sekullbe at comcast.net
Sat Jul 9 00:49:11 CDT 2005


I was playing the latest CVS recently and I noticed that my hit points
would drop sharply after a load/save. Looking at the save file, the
lev_array values were being saved wrongly- all 0s for hp and the first 4
levels of sp (grace seemed OK). Changing the save file didn't work; the
character always had the same point values regardless of what I put in
the file.

I traced the problem to login.c:620 (approximately):

    strncpy(pl->title, op->arch->clone.name,MAX_NAME);

which seems kind of weird to affect op->contr->levhp, but when I printed
all levhp values before and after, it was clearly causing the problem;
before that line all levhp values were what the save file said, and
after that they were all 0.


What I *think* is happening, and I'm not really a C programmer, is that
the strncpy is copying 48 bytes (MAX_NAME) of
op->arch->clone.name text into the 32 bytes (BIG_NAME) allocated in
player.h for a player title .  This then overwrites levhp and levsp, the
next elements of the 'pl' structure, with 16 bytes of nulls. This makes
sense given that all 10 levels of levhp and the first 4 levels of levsp
were zeroed out but the rest of levsp and all of levgrace were OK; that
adds up to 16 bytes.

I was able to fix it by changing BIG_NAME, at include/define.h:100, from
32 to 48.

I don't know if my fix in define.h is sufficient, or if it breaks
something somewhere else; I haven't tested with player-set titles. But
it works to load and save where that failed before.


the trivial patch:

*** include/define.h    29 May 2005 17:35:53 -0000      1.86
--- include/define.h    9 Jul 2005 03:38:51 -0000
***************
*** 97,103 ****
  #define MAX_ANIMATIONS                256

  #define MAX_NAME 48
! #define BIG_NAME 32
  #define MAX_EXT_TITLE 98

  /* Fatal variables: */
--- 97,103 ----
  #define MAX_ANIMATIONS                256

  #define MAX_NAME 48
! #define BIG_NAME 48
  #define MAX_EXT_TITLE 98

  /* Fatal variables: */




-- 
Scott E Kullberg  --><--  
     
     sekullbe at comcast.net
     
     
"The power of accurate observation is commonly called cynicism
by those who have not got it." - George Bernard Shaw


    
    


More information about the crossfire mailing list