]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
test: fix incorrect use of RAND_MAX
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 23 Sep 2021 07:34:47 +0000 (09:34 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 23 Sep 2021 13:51:35 +0000 (15:51 +0200)
On some systems (e.g. Solaris/OpenIndiana) rand() and random() have
different ranges. RAND_MAX is the maximum value returned by rand(),
but random() should always have a range of 0 through 2^31-1.

This fixes multiple failures in different tests.

test/unit/test.c

index 0f5638d8ed09f5f541780dac6090aa7ed319d1c5..94619c13372efece857b0a9dac065935bd7dd427 100644 (file)
@@ -90,7 +90,7 @@ main(int argc, char **argv)
 double
 TST_GetRandomDouble(double min, double max)
 {
-  return min + (double)random() / RAND_MAX * (max - min);
+  return min + random() / 2147483647.0 * (max - min);
 }
 
 void