Path: utzoo!mnetor!uunet!husc6!hao!noao!arizona!rupley From: rupley@arizona.edu (John Rupley) Newsgroups: comp.sources.bugs Subject: Re: A couple of nethack bug fixes Message-ID: <3308@megaron.arizona.edu> Date: 24 Dec 87 11:36:22 GMT References: <339@gaia.UUCP> Organization: U of Arizona CS Dept, Tucson Lines: 45 Summary: nethack 80286-specific bug in mklev.c In article <339@gaia.UUCP>, Jonathan Corbet writes > I found the answer to the bug I posted the other day, wherein the dungeon > was simply devoid of objects on Microport systems. I'm not sure of the > bug is in the nethack code, or in the Microport C compiler. The bug is in the code, which is broken for 80286 machines but not for the likes of Vaxen, where longs and ints have the same width. > What happens > is that the result of the somex() and somey() macros in mklev.c are "xchar" ^^^^^ In fact, they are longs, typed by the rand() call in the macros. > values, while the mkgold() and mkobj_at() routines expect full integers. > Most compilers will widen the values accordingly, but not here... Not quite... one long on the stack is read as two integers by the function, garbaging both integer parameters; thus the compiler is doing what it should. > The fix > is to go into mklev.c, and change lines like > mkgold (0L, somex (), somey ()); > to > mkgold (0L, (int) somex (), (int) somey); > and similarly with the mkobj_at() calls. I think there were only three > that needed to be changed. Right, but it is simpler to make the cast from long to int in the #defines for the somex and somey macros: #define somex() (int )((rand()%(croom->hx-croom->lx+1))+croom->lx) #define somey() (int )((rand()%(croom->hy-croom->ly+1))+croom->ly) some[xy] are defined as long also in fountain.c, but they are harmlessly truncated to int in the code. John Rupley uucp: ..{ihnp4 | hao!noao}!arizona!rupley!local internet: rupley!local@megaron.arizona.edu telex: 9103508679(JARJAR) (H) 30 Calle Belleza, Tucson AZ 85716 - (602) 325-4533 (O) Dept. Biochemistry, Univ. Arizona, Tucson AZ 85721 - (602) 621-3929