ZAangbad goes to (close enough to) 100% CPU due to the use of 64-bit
containers on 64-bit systems for what should be a 32-bit container for
the Rand_state values over in src/z-rand.c. One way to fix this might be
to use stdint.h types for s32b and friends:


--- src/h-type.h.orig   Fri May  4 18:21:57 2001
+++ src/h-type.h        Tue Jul 16 08:39:48 2019
@@ -108,19 +108,12 @@
 
 
 /* Signed/Unsigned 16 bit value */
-typedef signed short s16b;
-typedef unsigned short u16b;
+typedef int16_t s16b;
+typedef uint16_t u16b;
 
 /* Signed/Unsigned 32 bit value */
-#ifdef L64     /* 64 bit longs */
-typedef signed int s32b;
-typedef unsigned int u32b;
-#else
-typedef signed long s32b;
-typedef unsigned long u32b;
-#endif
-
-
+typedef int32_t s32b;
+typedef uint32_t u32b;
 
 
 /*** Pointers to all the basic types defined above ***/



A potential issue is the use of time(NULL) to set the seed; this might
better be done via arc4random, or not.


--- src/bldg.c.orig     Mon Aug 27 09:49:18 2001
+++ src/bldg.c  Tue Jul 16 08:39:48 2019
@@ -599,7 +599,7 @@
 
        /* Prevent savefile-scumming of the casino */
        Rand_quick = TRUE;
-       Rand_value = time(NULL);        
+       Rand_value = arc4random();      
        
        /* Return the amount of gold bet */
        return (wager);

--- src/dungeon.c.orig  Tue Aug 14 05:06:15 2001
+++ src/dungeon.c       Tue Jul 16 08:39:48 2019
@@ -3598,14 +3598,7 @@
                u32b seed;
 
                /* Basic seed */
-               seed = (time(NULL));
-
-#ifdef SET_UID
-
-               /* Mutate the seed on Unix machines */
-               seed = ((seed >> 3) * (getpid() * 2));
-
-#endif
+               seed = arc4random();
 
                /* Use the complex RNG */
                Rand_quick = FALSE;

--- src/main-dos.c.orig Sun Feb  4 14:11:56 2001
+++ src/main-dos.c      Tue Jul 16 08:39:48 2019
@@ -2185,7 +2185,7 @@
 
        /* Initialize the "complex" RNG for the midi-shuffle function */
        Rand_quick = FALSE;
-       Rand_state_init(time(NULL));
+       Rand_state_init(arc4random());
 
        /* Set the Angband colors/graphics/sound mode */
        Term_xtra_dos_react();

Reply via email to