summaryrefslogtreecommitdiff
path: root/nuttx/lib
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-12-12 18:27:20 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-12-12 18:27:20 +0000
commitcb26bb7a91709a9079754210521876ef890d4298 (patch)
tree2f1adbd757492b7ad776ad927223c2df31e52b3f /nuttx/lib
parentb735fa3903ad26747d304eed21aabd6ecee12acf (diff)
downloadpx4-nuttx-cb26bb7a91709a9079754210521876ef890d4298.tar.gz
px4-nuttx-cb26bb7a91709a9079754210521876ef890d4298.tar.bz2
px4-nuttx-cb26bb7a91709a9079754210521876ef890d4298.zip
Fix hcs12 integer overflows
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2327 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib')
-rw-r--r--nuttx/lib/lib_gmtimer.c16
-rw-r--r--nuttx/lib/lib_strftime.c6
2 files changed, 13 insertions, 9 deletions
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;
diff --git a/nuttx/lib/lib_strftime.c b/nuttx/lib/lib_strftime.c
index 7eed7d5a6..2e150aae7 100644
--- a/nuttx/lib/lib_strftime.c
+++ b/nuttx/lib/lib_strftime.c
@@ -189,8 +189,8 @@ size_t strftime(char *s, size_t max, const char *format, const struct tm *tm)
if (tm->tm_mon < 12)
{
str = g_abbrevmonthname[tm->tm_mon];
+ len = snprintf(dest, chleft, "%s", str);
}
- len = snprintf(dest, chleft, "%s", str);
}
break;
@@ -201,8 +201,8 @@ size_t strftime(char *s, size_t max, const char *format, const struct tm *tm)
if (tm->tm_mon < 12)
{
str = g_monthname[tm->tm_mon];
+ len = snprintf(dest, chleft, "%s", str);
}
- len = snprintf(dest, chleft, "%s", str);
}
break;
@@ -259,8 +259,8 @@ size_t strftime(char *s, size_t max, const char *format, const struct tm *tm)
if (tm->tm_mon < 12)
{
value = clock_daysbeforemonth(tm->tm_mon, clock_isleapyear(tm->tm_year)) + tm->tm_mday;
+ len = snprintf(dest, chleft, "%03d", value);
}
- len = snprintf(dest, chleft, "%03d", value);
}
break;