9
0
Fork 0

Fix hcs12 integer overflows

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@2327 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2009-12-12 18:27:20 +00:00
parent 6a2cd4dc28
commit 75f04d6533
2 changed files with 13 additions and 9 deletions

View File

@ -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;

View File

@ -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;