1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

gnrc/rpl: fix incorrect addition overflow check

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.
This commit is contained in:
Mingjie Shen 2023-06-17 02:25:11 -04:00
parent 5d32c95c16
commit fe92f676b4

View File

@ -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;
}