[net.games.hack] wand of core dumping

cliff@unmvax.UUCP (04/08/85)

Lately I haven't been able to get mail to mcvax.  This letter concerns
hack 1.0.  On our SUN, wands of wishing cause core dumps when items are
misspelled.  I found the problem to be related to NROFOBJECTS being defined
improperly.  My quick patch was to change the following line (we are still
running hack 1.0).

436c436
< 	while(i <= NROFOBJECTS && (!let || objects[i].oc_olet == let)){
---
> 	while(objects[i].oc_name && (!let || objects[i].oc_olet == let)){

				--Cliff

aeb@mcvax.UUCP (Andries Brouwer) (04/10/85)

In article <774@unmvax.UUCP> cliff@unmvax.UUCP writes:
> Lately I haven't been able to get mail to mcvax.  This letter concerns
> hack 1.0.  On our SUN, wands of wishing cause core dumps when items are
> misspelled.  I found the problem to be related to NROFOBJECTS being defined
> improperly.  My quick patch was to change the following line (we are still
> running hack 1.0).
> 
> 436c436
> < 	while(i <= NROFOBJECTS && (!let || objects[i].oc_olet == let)){
> ---
> > 	while(objects[i].oc_name && (!let || objects[i].oc_olet == let)){

Thanks for the bug report; in fact your letter reached me, but perhaps my
reply failed to reach you. Anyway, I don't think there is anything wrong
with NROFOBJECTS, the problem is rather that strcmp(p,q) is done where q
may be 0. Your attempt at a fix only solves part of the problem - a core
dump is still possible - while on the other hand it makes asking for certain
objects impossible. I think the following would be better (the line numbers
are from hack.objnam.c version 1.0.2 but the fix works equally well on
earlier versions).
# diff hack.objnam.c (new)  hack.objnam.c (old)
498,501c498
< 		register char *zn = objects[i].oc_name;
< 
< 		if(!zn) goto nxti;
< 		if(an && strcmp(an, zn))
---
> 		if(an && strcmp(an, objects[i].oc_name))
503c500
< 		if(dn && (!(zn = objects[i].oc_descr) || strcmp(dn, zn)))
---
> 		if(dn && strcmp(dn, objects[i].oc_descr))
505c502
< 		if(un && (!(zn = objects[i].oc_uname) || strcmp(un, zn)))
---
> 		if(un && strcmp(un, objects[i].oc_uname))