From cb26bb7a91709a9079754210521876ef890d4298 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 12 Dec 2009 18:27:20 +0000 Subject: Fix hcs12 integer overflows git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2327 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/lib/lib_gmtimer.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'nuttx/lib/lib_gmtimer.c') diff --git a/nuttx/lib/lib_gmtimer.c b/nuttx/lib/lib_gmtimer.c index e7514fd1a..a8555edc6 100644 --- a/nuttx/lib/lib_gmtimer.c +++ b/nuttx/lib/lib_gmtimer.c @@ -50,6 +50,10 @@ * Definitions ****************************************************************************/ +#define SEC_PER_MIN ((time_t)60) +#define SEC_PER_HOUR ((time_t)60 * SEC_PER_MIN) +#define SEC_PER_DAY ((time_t)24 * SEC_PER_HOUR) + /**************************************************************************** * Private Type Declarations ****************************************************************************/ @@ -310,14 +314,14 @@ struct tm *gmtime_r(const time_t *clock, struct tm *result) /* Convert to days, hours, minutes, and seconds since the EPOCH */ - jdn = time / (24*60*60); - time -= (24*60*60) * jdn; + jdn = time / SEC_PER_DAY; + time -= SEC_PER_DAY * jdn; - hour = time / (60*60); - time -= (60*60) * hour; + hour = time / SEC_PER_HOUR; + time -= SEC_PER_HOUR * hour; - min = time / 60; - time -= 60 * min; + min = time / SEC_PER_MIN; + time -= SEC_PER_MIN * min; sec = time; -- cgit v1.2.3