Package: dealer / 20161012-4

dealer.c Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Mask k so zero52[k] doesn't overflow

--- a/dealer.c
+++ b/dealer.c
@@ -51,6 +51,7 @@
 #define DEFAULT_MODE STAT_MODE
 #define RANDBITS 16
 #define NRANDVALS (1<<RANDBITS)
+#define NRANDMASK (NRANDVALS-1)
 
 #ifdef MSDOS
   char *crlf = "\r\n";
@@ -866,7 +867,7 @@
              /* Upper bits most random */
              k = (RANDOM () >> (31 - RANDBITS));
 #endif /* STD_RAND */
-             j = zero52[k];
+             j = zero52[k & NRANDMASK];
            } while (j == 0xFF);
         } while (stacked_pack[j] != NO_CARD);
 
@@ -1621,7 +1622,7 @@
       }
     }
   if (argc - optind > 2 || errflg) {
-    fprintf (stderr, "Usage: %s [-emvu] [-s seed] [-p num] [-v num] [inputfile]\n", argv[0]);
+    fprintf (stderr, "Usage: %s [-023ehuvmqV] [-p n] [-g n] [-s seed] [-l n] [inputfile]\n", argv[0]);
     exit (-1);
   }
   if (optind < argc && freopen (input_file = argv[optind], "r", stdin) == NULL) {