From c6edf41a7401e3cfcad9d9ce703bdef5055c196b Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Fri, 8 Feb 2019 11:39:18 -0800 Subject: [PATCH] test time: Fixed bad assumption about RAND_MAX (#11414) usleep range was up to 2147 Seconds Per open group: The rand() function shall compute a sequence of pseudo-random integers in the range [0, {RAND_MAX}] with a period of at least 2^32 {RAND_MAX} Maximum value returned by rand(); at least 32767. /* Maximum value returned by rand(). Must be a minimum of 32767. */ #define RAND_MAX INT_MAX and #define INT_MAX 2147483647 --- src/systemcmds/tests/test_time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/systemcmds/tests/test_time.c b/src/systemcmds/tests/test_time.c index 235abcf5f3..4463701dba 100644 --- a/src/systemcmds/tests/test_time.c +++ b/src/systemcmds/tests/test_time.c @@ -104,7 +104,7 @@ int test_time(int argc, char *argv[]) /* loop checking the time */ for (unsigned i = 0; i < 100; i++) { - usleep(rand()); + usleep(rand() % SHRT_MAX); uint32_t flags = px4_enter_critical_section();