<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40098 >
In PR#40073, I moved the code from client/tilespec.c into utility/rand.c,
but now it seems to assert() on larger maps. Changed the assert() to allow
larger values. And use standard header definitions!
Index: utility/rand.c
===================================================================
--- utility/rand.c (revision 14405)
+++ utility/rand.c (working copy)
@@ -265,7 +265,7 @@
#define SMALL_PRIME (1009)
/* Check for overflow and underflow */
- assert((int)(seed * LARGE_PRIME) > 0);
+ assert(seed < MAX_UINT32 / LARGE_PRIME);
assert(size < SMALL_PRIME);
assert(size > 0);
result = ((seed * LARGE_PRIME) % SMALL_PRIME) % size;
Index: utility/rand.h
===================================================================
--- utility/rand.h (revision 14405)
+++ utility/rand.h (working copy)
@@ -13,12 +13,14 @@
#ifndef FC__RAND_H
#define FC__RAND_H
+#include <stdint.h>
+
#include "shared.h" /* bool type */
/* This is duplicated in shared.h to avoid extra includes: */
#define MAX_UINT32 0xFFFFFFFF
-typedef unsigned int RANDOM_TYPE;
+typedef uint32_t RANDOM_TYPE;
typedef struct {
RANDOM_TYPE v[56];
_______________________________________________
Freeciv-dev mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-dev