From dc334d60b27f9a99cea1926a0b74e899c42f9487 Mon Sep 17 00:00:00 2001 From: mhsin Date: Tue, 18 Dec 2007 09:36:52 +0000 Subject: Revert r3704 and add saturation check for gettime(). git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3705 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/stuff.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c index 9d08e2d2..90c0988a 100644 --- a/mbbsd/stuff.c +++ b/mbbsd/stuff.c @@ -216,6 +216,7 @@ gettime(int line, time4_t dt, const char*head) char yn[7]; int i; struct tm *ptime = localtime4(&dt), endtime; + time_t t; memcpy(&endtime, ptime, sizeof(struct tm)); snprintf(yn, sizeof(yn), "%4d", ptime->tm_year + 1900); @@ -223,13 +224,7 @@ gettime(int line, time4_t dt, const char*head) i=strlen(head); do { getdata_buf(line, i, " 西元年:", yn, 5, LCECHO); - } while ((endtime.tm_year = atoi(yn) - 1970) < 0 || endtime.tm_year > 200); - - // current time4_t is signed. - // safe range: 2038(signed)~1970(unsigned) - if (endtime.tm_year > 137) endtime.tm_year = 137; - if (endtime.tm_year < 70) endtime.tm_year = 70; - + } while ((endtime.tm_year = atoi(yn) - 1900) < 0 || endtime.tm_year > 200); snprintf(yn, sizeof(yn), "%d", ptime->tm_mon + 1); do { getdata_buf(line, i+15, "月:", yn, 3, LCECHO); @@ -242,7 +237,13 @@ gettime(int line, time4_t dt, const char*head) do { getdata_buf(line, i+33, "時(0-23):", yn, 3, LCECHO); } while ((endtime.tm_hour = atoi(yn)) < 0 || endtime.tm_hour > 23); - return mktime(&endtime); + t = mktime(&endtime); + /* saturation check */ + if(t < 0) + t = 1; + if(t > INT_MAX) + t = INT_MAX; + return t; } // synchronize 'now' -- cgit v1.2.3