Skip to content

Commit

Permalink
- fixed generation of random negative numbers causing the pick_random…
Browse files Browse the repository at this point in the history
…_fd method to fail.
  • Loading branch information
sp-martin committed Jun 13, 2024
1 parent 4b254d8 commit 30cace2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion port/android/ipadapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion port/esp32/adapter/src/ipadapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion port/linux/ipadapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 30cace2

Please sign in to comment.