The latest versions of all of the files you talked about are in their correct places. I ran it through a debugger, and the problem occurs in arch.c, line 640, in the hasharch function.
Code: Select all
unsigned long
hasharch(const char *str, int tablesize) {
unsigned long hash = 0;
int i = 0;
unsigned rot = 0;
const char *p;
for (p = str; i < MAXSTRING && *p; p++, i++) { // this is line 640
hash ^= (unsigned long) *p << rot;
rot += 2;
if (rot >= (sizeof(long) - sizeof(char)) * 8)
rot = 0;
}
return (hash % tablesize);
}
The Watch window says that when the error occurs, str is set to "", or 0x00000000.
EDIT: Fixed this bug, I added this right before the for statement:
Now there's another bug, when the treasures are being loaded. I'm working on fixing that one right now. This one is in treasure.c, line 140, in the load_treasure function. It's caused by an strcmp in an else if statement:
Code: Select all
static treasure *load_treasure(FILE *fp, int *line) {
char buf[MAX_BUF], *cp, variable[MAX_BUF];
treasure *t=get_empty_treasure();
int value;
nroftreasures++;
while(fgets(buf,MAX_BUF,fp)!=NULL) {
(*line)++;
if(*buf=='#')
continue;
if((cp=strchr(buf,'\n'))!=NULL)
*cp='\0';
cp=buf;
while(isspace(*cp)) /* Skip blanks */
cp++;
if(sscanf(cp,"arch %s",variable)) {
if((t->item=find_archetype(variable))==NULL)
LOG(llevError,"Treasure lacks archetype: %s\n",variable);
} else if (sscanf(cp, "list %s", variable))
t->name = add_string(variable);
else if (sscanf(cp, "change_name %s", variable))
t->change_arch.name = add_string(variable);
else if (sscanf(cp, "change_title %s", variable))
t->change_arch.title = add_string(variable);
else if (sscanf(cp, "change_slaying %s", variable))
t->change_arch.slaying = add_string(variable);
else if(sscanf(cp,"chance %d",&value))
t->chance=(uint8) value;
else if(sscanf(cp,"nrof %d",&value))
t->nrof=(uint16) value;
else if(sscanf(cp,"magic %d",&value))
t->magic=(uint8) value;
else if(!strcmp(cp,"yes")) // bug occurs here
t->next_yes=load_treasure(fp, line);
else if(!strcmp(cp,"no")) // and probably here
t->next_no=load_treasure(fp, line);
else if(!strcmp(cp,"end")) // and probably here
return t;
else if(!strcmp(cp,"more")) { // and probably here
t->next=load_treasure(fp, line);
return t;
} else
LOG(llevError,"Unknown treasure-command: '%s', last entry %s, line %d\n",
cp,t->name?t->name:"null", *line);
}
LOG(llevError,"treasure lacks 'end'.\n");
return t;
}
And, once again, it is caused by an empty string. Any ideas?