Skip to content

Commit

Permalink
AIX, HP-UX, and SunOS needs to use rand() rather than random()
Browse files Browse the repository at this point in the history
The selftest for zhash was failing on these platforms because random()
returns up to 2^31-1 and RAND_MAX is set to 2^15-1.  Because of this,
the random index picked in the selftest by randof() was overflowing
the array.

Also, ifaddrs.h does not exist on these platforms
  • Loading branch information
AJ Lewis committed Nov 9, 2011
1 parent 5b58830 commit 3e7fc85
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/czmq_prelude.h
Expand Up @@ -304,7 +304,7 @@
# include <sys/file.h>
# include <sys/wait.h>
# include <netinet/in.h> // Must come before arpa/inet.h
# if (!defined (__UTYPE_ANDROID))
# if (!defined (__UTYPE_ANDROID)) && (!defined (__UTYPE_IBMAIX)) && (!defined (__UTYPE_HPUX)) && (!defined (__UTYPE_SUNOS))
# include <ifaddrs.h>
# endif
# if (!defined (__UTYPE_BEOS))
Expand Down Expand Up @@ -402,7 +402,7 @@ typedef unsigned int qbyte; // Quad byte = 32 bits
#define tblsize(x) (sizeof (x) / sizeof ((x) [0]))
#define tbllast(x) (x [tblsize (x) - 1])
// Provide random number from 0..(num-1)
#if (defined (__WINDOWS__))
#if (defined (__WINDOWS__)) || (defined (__UTYPE_IBMAIX)) || (defined (__UTYPE_HPUX)) || (defined (__UTYPE_SUNOS))
# define randof(num) (int) ((float) (num) * rand () / (RAND_MAX + 1.0))
#else
# define randof(num) (int) ((float) (num) * random () / (RAND_MAX + 1.0))
Expand Down

0 comments on commit 3e7fc85

Please sign in to comment.