Crossfire Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: CF: pray/claw/magic xp
- To: crossfire (at) ifi.uio.no
- Subject: Re: CF: pray/claw/magic xp
- From:
- Date: Thu, 2 May 1996 00:40:06 -0700
- Sender:
>Well, as of CF0.92.4 '#' comments entered the skill_params
>file...unfortuneately read_skill_params(), which reinitializes
>the skills array -- skills[], fails when it sees comment
>lines in the file skill_params.
>
>The change in skill_params file is new as of 0.92.4, so there
>is still one more bug to find (??), ill continue on looking
>tonight. The short patch below should be applied to skill_util.c,
>or alternatively, edit lib/skill_params so that all '#' lines
>are removed.
>
> -b.t.
Actually, there appears too be more to it than that, first of all,
in read_skill_params(), skill_name was being declared as skill_name[30],
but used in the fgets as if it were skill_name[50]. Not only this, but
if the '#' comments were over 50 chars (as the third line in the default
skill_params file) then it would pickup half the line, then the second half
(but without a '#') on the next iteration. We should make the buffer big
enough to scan in a full line (80 chars + \n + '\0') at a time. Enclosed
is a patch (note that fgets will only read n-1 chars, saving it's own
space for null termination). In the same patch, I changed skill_attrib to
skill_attrib[82] as well, in case some idiot spreads his attributes out
over the line.
Also, lookup_skill_by_name wasn't properly returning -1 when a skill name
wasn't found. Enclosed is a patch for this as well. Alternatively,
you could change
if(skillnr==NROFSKILLS) skillnr=-1;
to
if(skillnr==NROFSKILLS-1) skillnr=-1;
but the other way seemed cleaner to me.
This does, however, make change_skill silently fail when you try to use
a non-existent skill. But it looks it would relatively ugly to have it
generate a sensible error message.
Just out of curiosity (since I am pretty new to this list), is mailing to this
list considered an adequate form of bug/patch submission, or to I need to mail
Mark seperately?
Steve
*** skill_util.c.orig Wed May 1 23:44:46 1996
--- skill_util.c Wed May 1 23:50:41 1996
***************
*** 464,471 ****
void read_skill_params () {
FILE *skill_params;
char fname[MAX_BUF];
! char skill_name[30];
! char skill_attrib[50];
int cat,bexp,time,stat1,stat2,stat3,skillindex;
float lexp;
--- 464,471 ----
void read_skill_params () {
FILE *skill_params;
char fname[MAX_BUF];
! char skill_name[82];
! char skill_attrib[82];
int cat,bexp,time,stat1,stat2,stat3,skillindex;
float lexp;
***************
*** 478,484 ****
while(!feof(skill_params))
{
! fgets(skill_name,49,skill_params);
if(*skill_name=='#') continue;
skillindex=lookup_skill_by_name(skill_name);
--- 478,484 ----
while(!feof(skill_params))
{
! fgets(skill_name,82,skill_params);
if(*skill_name=='#') continue;
skillindex=lookup_skill_by_name(skill_name);
***************
*** 486,492 ****
LOG(llevError,"\nskill_params has unrecognized skill: %s",skill_name);
continue;
}
! fgets(skill_attrib,49,skill_params);
sscanf(skill_attrib,"%d %d %d %f %d %d %d",
&cat,&time,&bexp,&lexp,&stat1,&stat2,&stat3);
skills[skillindex].category=cat;
--- 486,492 ----
LOG(llevError,"\nskill_params has unrecognized skill: %s",skill_name);
continue;
}
! fgets(skill_attrib,82,skill_params);
sscanf(skill_attrib,"%d %d %d %f %d %d %d",
&cat,&time,&bexp,&lexp,&stat1,&stat2,&stat3);
skills[skillindex].category=cat;
***************
*** 511,518 ****
nmlen = strcspn(string," ");
strncpy(name,string,nmlen);
! while(strncmp(name,skills[skillnr].name,MIN(strlen(skills[skillnr].name),nmlen))
! && skillnr < (NROFSKILLS - 1)) {
skillnr++;
}
--- 511,517 ----
nmlen = strcspn(string," ");
strncpy(name,string,nmlen);
! while(skillnr < NROFSKILLS && strncmp(name,skills[skillnr].name,MIN(strlen(skills[skillnr].name),nmlen))) {
skillnr++;
}