From 1bdec853e15ba5b94924f4f0eabf9eae7b5f7780 Mon Sep 17 00:00:00 2001 From: Cristiano De Alti Date: Sat, 5 Nov 2016 22:46:42 +0100 Subject: [PATCH] Prevent interger overflow on the AVR Compiling examples/er-rest-example for the avr-raven gives: integer overflow in expression [-Woverflow] On the AVR int is 16 bit and some calculations may overflow. This happens for example with multiplications involving CLOCK_SECOND where all the operands are of type int. Casting one of the operands to clock_time_t forces the arithmetic to clock_time_t without increasing the size of the program (the calculation is performed at compile time). --- core/net/link-stats.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/net/link-stats.c b/core/net/link-stats.c index a2f99e729..64008989b 100644 --- a/core/net/link-stats.c +++ b/core/net/link-stats.c @@ -51,7 +51,7 @@ /* Maximum value for the freshness counter */ #define FRESHNESS_MAX 16 /* Statistics with no update in FRESHNESS_EXPIRATION_TIMEOUT is not fresh */ -#define FRESHNESS_EXPIRATION_TIME (10 * 60 * CLOCK_SECOND) +#define FRESHNESS_EXPIRATION_TIME (10 * 60 * (clock_time_t)CLOCK_SECOND) /* EWMA (exponential moving average) used to maintain statistics over time */ #define EWMA_SCALE 100 @@ -206,6 +206,6 @@ void link_stats_init(void) { nbr_table_register(link_stats, NULL); - ctimer_set(&periodic_timer, 60 * CLOCK_SECOND * FRESHNESS_HALF_LIFE, + ctimer_set(&periodic_timer, 60 * (clock_time_t)CLOCK_SECOND * FRESHNESS_HALF_LIFE, periodic, NULL); }