GNU bug report logs - #32605
[w64] (random) never returns negative

Previous Next

Package: emacs;

Reported by: f.j.wright <at> live.co.uk

Date: Sat, 1 Sep 2018 17:21:01 UTC

Severity: normal

Tags: confirmed

Found in version 26.1

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Eli Zaretskii <eliz <at> gnu.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: andrewjmoreton <at> gmail.com, 32605 <at> debbugs.gnu.org
Subject: bug#32605: [w64] (random) never returns negative
Date: Thu, 12 Aug 2021 16:42:35 +0300
> From: Lars Ingebrigtsen <larsi <at> gnus.org>
> Cc: 32605 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
> Date: Thu, 12 Aug 2021 15:17:46 +0200
> 
> Andy Moreton <andrewjmoreton <at> gmail.com> writes:
> 
> >> This bug seems specific to 64 bit Windows builds.
> >
> > ON 64bit Windows, sysdep.c sets RAND_BITS to 31, but random (in w32.c)
> > only provides 30 bits. It looks like the mixing in get_random does not
> > result in the top fixnum bit being set.
> 
> So it's this:
> 
> int
> random (void)
> {
>   /* rand_as183 () gives us 15 random bits...hack together 30 bits.  */
>   return ((rand_as183 () << 15) | rand_as183 ());
> }
> 
> So running rand_as183 and taking another bit from that might do the
> trick?  Eli, do you have any comments here?

The 'random' emulation in w32.c was never adapted to w64.

Instead of calling rand_as183 one more time, perhaps it's better to
trivially transform the value we have?  Something like

    int val = ((rand_as183 () << 15) | rand_as183 ());
  #ifdef __x86_64__
    return 2 * val - 0x3FFFFFFF;
  #else
    return val;
  #endif

Andy, can you test this, please?




This bug report was last modified 4 years ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.