Skip to content

Commit

Permalink
link_sim: avoid dividing by 0
Browse files Browse the repository at this point in the history
Reported in #5

Signed-off-by: Olivier Tilmans <[email protected]>
  • Loading branch information
oliviertilmans committed Oct 27, 2015
1 parent 7aaafd9 commit bbb3c4a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions link_sim.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ static inline int simulate_link(char *buf, int len)
/* Do we want to simulate delay? */
if (delay) {
/* Random delay to add is capped to 10s */
unsigned int applied_delay = RAND_PERCENT > 49 ?
delay + rand() % jitter :
delay - rand() % jitter;
unsigned int applied_delay = jitter ?
(RAND_PERCENT > 49 ?
delay + rand() % jitter :
delay - rand() % jitter) :
delay;
applied_delay %= 10000;
LOG_PKT_FMT(buf, "Delayed packet by %u ms\n", applied_delay);
/* Create a slot for the packet queue */
Expand Down

0 comments on commit bbb3c4a

Please sign in to comment.