From fe92f676b4f5facb49ebae0e3f7d4bbc499e07bf Mon Sep 17 00:00:00 2001 From: Mingjie Shen Date: Sat, 17 Jun 2023 02:25:11 -0400 Subject: [PATCH] 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. --- sys/net/gnrc/routing/rpl/of0.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/net/gnrc/routing/rpl/of0.c b/sys/net/gnrc/routing/rpl/of0.c index 01a69d0191..282964d5cd 100644 --- a/sys/net/gnrc/routing/rpl/of0.c +++ b/sys/net/gnrc/routing/rpl/of0.c @@ -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; }