From 30cace2b103a295ae4cbef5dc80db6f454c54a7e Mon Sep 17 00:00:00 2001 From: sp-martin Date: Thu, 13 Jun 2024 18:28:34 +0000 Subject: [PATCH] - fixed generation of random negative numbers causing the pick_random_fd method to fail. --- port/android/ipadapter.c | 2 +- port/esp32/adapter/src/ipadapter.c | 2 +- port/linux/ipadapter.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/port/android/ipadapter.c b/port/android/ipadapter.c index e47c176a1..b910f90b0 100644 --- a/port/android/ipadapter.c +++ b/port/android/ipadapter.c @@ -815,7 +815,7 @@ static int pick_random_fd(const fd_set *sourcefds, int fd_count, int max_fd) { assert(fd_count > 0); - int random_rfd = (int)oc_random_value() % fd_count; + int random_rfd = (int)(oc_random_value() % fd_count); for (int i = 0; i <= max_fd; i++) { if (FD_ISSET(i, sourcefds)) { if (--fd_count == random_rfd) { diff --git a/port/esp32/adapter/src/ipadapter.c b/port/esp32/adapter/src/ipadapter.c index 40cb2a463..c7f52d64d 100644 --- a/port/esp32/adapter/src/ipadapter.c +++ b/port/esp32/adapter/src/ipadapter.c @@ -840,7 +840,7 @@ static int pick_random_fd(const fd_set *sourcefds, int fd_count, int max_fd) { assert(fd_count > 0); - int random_rfd = (int)oc_random_value() % fd_count; + int random_rfd = (int)(oc_random_value() % fd_count); for (int i = 0; i <= max_fd; i++) { if (FD_ISSET(i, sourcefds)) { if (--fd_count == random_rfd) { diff --git a/port/linux/ipadapter.c b/port/linux/ipadapter.c index 1ed0a2a94..d0831f154 100644 --- a/port/linux/ipadapter.c +++ b/port/linux/ipadapter.c @@ -937,7 +937,7 @@ static int pick_random_fd(const fd_set *sourcefds, int fd_count, int max_fd) { assert(fd_count > 0); - int random_rfd = (int)oc_random_value() % fd_count; + int random_rfd = (int)(oc_random_value() % fd_count); for (int i = 0; i <= max_fd; i++) { if (FD_ISSET(i, sourcefds)) { if (--fd_count == random_rfd) {