From 9c66df6de1dedc2fa0cf9e492641d2891d53b535 Mon Sep 17 00:00:00 2001 From: dak664 Date: Mon, 13 Dec 2010 16:52:02 +0000 Subject: [PATCH] Fix ancient RAND_MAX compiler warning --- core/lib/random.c | 5 ++++- core/lib/random.h | 6 ++++-- core/net/rpl/rpl-timers.c | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/lib/random.c b/core/lib/random.c index a651e281b..91db6c7b7 100644 --- a/core/lib/random.c +++ b/core/lib/random.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: random.c,v 1.4 2010/10/24 21:02:23 adamdunkels Exp $ + * @(#)$Id: random.c,v 1.5 2010/12/13 16:52:02 dak664 Exp $ */ @@ -47,6 +47,9 @@ random_init(unsigned short seed) unsigned short random_rand(void) { +/* In gcc int rand() uses RAND_MAX and long random() uses RANDOM_MAX=0x7FFFFFFF */ +/* RAND_MAX varies depending on the architecture */ + return (unsigned short)rand(); } /*---------------------------------------------------------------------------*/ diff --git a/core/lib/random.h b/core/lib/random.h index c2f89ebdd..d63cb55b0 100644 --- a/core/lib/random.h +++ b/core/lib/random.h @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: random.h,v 1.1 2006/06/17 22:41:18 adamdunkels Exp $ + * @(#)$Id: random.h,v 1.2 2010/12/13 16:52:02 dak664 Exp $ */ #ifndef __RANDOM_H__ #define __RANDOM_H__ @@ -46,6 +46,8 @@ void random_init(unsigned short seed); */ unsigned short random_rand(void); -#define RANDOM_MAX 65535U +/* In gcc int rand() uses RAND_MAX and long random() uses RANDOM_MAX */ +/* Since random_rand casts to unsigned short, we'll use this maxmimum */ +#define RANDOM_RAND_MAX 65535U #endif /* __RANDOM_H__ */ diff --git a/core/net/rpl/rpl-timers.c b/core/net/rpl/rpl-timers.c index 2eab6f782..298a436b6 100644 --- a/core/net/rpl/rpl-timers.c +++ b/core/net/rpl/rpl-timers.c @@ -32,7 +32,7 @@ * * This file is part of the Contiki operating system. * - * $Id: rpl-timers.c,v 1.13 2010/11/03 15:41:23 adamdunkels Exp $ + * $Id: rpl-timers.c,v 1.14 2010/12/13 16:52:02 dak664 Exp $ */ /** * \file @@ -93,7 +93,7 @@ new_dio_interval(rpl_dag_t *dag) /* random number between I/2 and I */ time = time >> 1; - time += (time * random_rand()) / RANDOM_MAX; + time += (time * random_rand()) / RANDOM_RAND_MAX; dag->dio_next_delay -= time; dag->dio_send = 1;