Tape random seeds break across 32/64-bit platforms

Found a bug in R'n'D? Report it here!

Moderators: Flumminator, Zomis

Post Reply
Anonycat
Posts: 47
Joined: Thu Mar 27, 2008 4:45 am

Tape random seeds break across 32/64-bit platforms

Post by Anonycat »

Last year, I rebuilt my machine using modern parts, which obviously included a 64-bit processor and OS, after I had been on a 32-bit system for the previous 9 years. Soon after that, I recompiled my custom RnD installation for the new architecture, and tried to play back some of my existing collection of tapes, only to find that they almost never ran successfully to completion.

As I would soon find out, the culprit was the fact that the random generator declared variables of type "long", which actually have different sizes from the old platform to the new one. In particular, there's a point where the least random bit is supposedly discarded for entropy reasons (random.c:244) which makes reference to LONG_MAX, and that now consists of 63 straight ones (9 quintillion) instead of 31 (2 billion). Taking the bitwise AND of a preexisting 32-bit number with 63 ones doesn't accomplish a whole lot, making it easy to see where it starts to diverge.

Since the comments to that file specifically mention 31/32 bits as the intended data width, compatibility can be restored by replacing all references to the "long" type in the random code by "int32_t" (or "uint32_t" where it's unsigned). Affected files:
libgame/random.c, random.h (everywhere; the mentions of LONG_MAX can be replaced by the constant 2147483647)
libgame/misc.c:379,384,392,397, misc.h:41
main.c:12236,12238,13026,16431
network.c:311,506
tape.c:552,557, tape.h:104,144
tools.c:6748, tools.h:205
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: Tape random seeds break across 32/64-bit platforms

Post by Holger »

This issue should be fixed since 3.3.1.0, and R'n'D should now be fully 64-bit aware.
Post Reply