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).
This commit is contained in:
parent
1ebceb8f23
commit
1bdec853e1
1 changed files with 2 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue