Skip to content

Commit

Permalink
test time: Fixed bad assumption about RAND_MAX (#11414)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
David Sidrane authored and dagar committed Feb 8, 2019
1 parent 2217faf commit c6edf41
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/systemcmds/tests/test_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit c6edf41

Please sign in to comment.