Xref: utzoo comp.sources.games.bugs:22 rec.games.hack:2075 Path: utzoo!utgpu!water!watmath!clyde!rutgers!sri-spam!ames!sdcsvax!ucsdhub!hp-sdd!hplabs!sdcrdcf!sdcsmb!sea!eggert From: eggert@sea.sm.unisys.com (Paul Eggert) Newsgroups: comp.sources.games.bugs,rec.games.hack Subject: nethack bug fix: 16-bit hosts can send you to heaven involuntarily Message-ID: <4@sea.sm.unisys.com> Date: 29 Jan 88 17:25:02 GMT Reply-To: eggert@sea.sm.unisys.com (Paul Eggert) Organization: Unisys Santa Monica Lines: 36 A portability bug in nethack's rnd.c can affect adventurers on 16-bit hosts. The bug caused an adventurer deep in the dungeon to be sent to heaven involuntarily by a teleport trap. His screams of disappointment caused me to investigate the problem. Here is a fix that makes integer overflow (and thus heaven) less likely by a factor of 2^32 on such machines. *************** *** 43,55 **** return(tmp); } ! rnz(x) ! register x; { ! register tmp = 1000; tmp += rn2(1000); tmp *= rne(4); if (rn2(2)) { x *= tmp; x /= 1000; } else { x *= 1000; x /= tmp; } ! return(x); } --- 43,56 ---- return(tmp); } ! rnz(i) ! int i; { ! register long x = i; ! register long tmp = 1000; tmp += rn2(1000); tmp *= rne(4); if (rn2(2)) { x *= tmp; x /= 1000; } else { x *= 1000; x /= tmp; } ! return((int)x); }