Skip to content

Commit

Permalink
gnrc/rpl: fix incorrect addition overflow check
Browse files Browse the repository at this point in the history
Checking for overflow of integer addition by comparing against one of
the arguments of the addition does not work when the result of the
addition is automatically promoted to a larger type.

Fix by using an explicit cast to make sure that the result of the
addition is not implicitly converted to a larger type.
  • Loading branch information
szsam committed Jun 17, 2023
1 parent 5d32c95 commit fe92f67
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion sys/net/gnrc/routing/rpl/of0.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ uint16_t calc_rank(gnrc_rpl_dodag_t *dodag, uint16_t base_rank)
add = CONFIG_GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE;
}

if ((base_rank + add) < base_rank) {
if ((uint16_t)(base_rank + add) < base_rank) {
return GNRC_RPL_INFINITE_RANK;
}

Expand Down

0 comments on commit fe92f67

Please sign in to comment.