ZetaMUCK / zetamuck

A fork of ProtoMUCK with an emphasis on stability.
Other
1 stars 0 forks source link

seed precision loss in random.c; varies between 32/64-bit #28

Closed blightbow closed 9 years ago

blightbow commented 9 years ago

Original issue 28 created by ZetaMUCK on 2014-07-15T06:23:02.000Z:

Stealing a bug from Proto's old Sourceforge site: http://sourceforge.net/p/protomuck/bugs/190/

Akari demonstrated this bug to me when a game she codes for was moved from a 32-bit host to a 64-bit host; seed consistency was violated.

Quoting the SF bug: Even though the source to random.c has changed slightly since I last checked, it seems that the last 12 bytes of the 16 byte digest for srand are not being added to the digest, as shown in function rnd (void buffer) below: MD5hash(digest, digest, sizeof(unsigned long)); The problem is using sizeof(unsigned long) (which on 32-bit machines tends to be 4 bytes and on 64-bit machines tends to be 8 bytes), when in fact the digest size is 16 bytes. This problem is furthered by the fact that in the function init_seed (char seed), the digest is allocated using sizeof(unsigned long) * 4, which can differ on 64-bit machines, where the unsigned long is not 32 bits: if (!(digest = (unsigned long ) malloc(sizeof(unsigned long) \ 4))) { In both these cases, none of this will cause a crash, but it does cause a significant reduction in the precision of the random seed.

blightbow commented 9 years ago

Comment #1 originally posted by ZetaMUCK on 2014-07-20T03:10:25.000Z:

No longer applicable after review of code.