This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH [4/n]: Support 64bit time_t and 32bit long


On Thu, Mar 15, 2012 at 12:54 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, Mar 15, 2012 at 12:52 PM, Roland McGrath <roland@hack.frob.com> wrote:
>>> Linux/x32 uses 64bit time_t and 32bit long. ?This patch updates
>>> ydhms_diff to support TIME_T_MAX != LONG_MAX. ?It also updates __offtime
>>> to propeyly check overflow when converting time_t to long.
>>
>> These are two separate changes. ?The mktime change can go in no problem.
>> The offtime change needs more consideration.
>>
>>
>
> I will resubmit them separately.
>

Here is the patch for offtime.

Thanks.

-- 
H.J.
---

2012-03-15  H.J. Lu  <hongjiu.lu@intel.com>

	* time/offtime.c (__offtime): Add more overflow check.
2012-03-15  H.J. Lu  <hongjiu.lu@intel.com>
 
	* time/offtime.c (__offtime): Add more overflow check.

diff --git a/time/offtime.c b/time/offtime.c
index 1ccd6a8..3746b99 100644
--- a/time/offtime.c
+++ b/time/offtime.c
@@ -35,6 +35,8 @@ __offtime (t, offset, tp)
   const unsigned short int *ip;
 
   days = *t / SECS_PER_DAY;
+  if (days != *t / SECS_PER_DAY)
+    goto overflow;
   rem = *t % SECS_PER_DAY;
   rem += offset;
   while (rem < 0)
@@ -65,6 +67,9 @@ __offtime (t, offset, tp)
       /* Guess a corrected year, assuming 365 days per year.  */
       long int yg = y + days / 365 - (days % 365 < 0);
 
+      if (yg < 0)
+	goto overflow;
+
       /* Adjust DAYS and Y to match the guessed year.  */
       days -= ((yg - y) * 365
 	       + LEAPS_THRU_END_OF (yg - 1)
@@ -74,6 +79,7 @@ __offtime (t, offset, tp)
   tp->tm_year = y - 1900;
   if (tp->tm_year != y - 1900)
     {
+overflow:
       /* The year cannot be represented due to overflow.  */
       __set_errno (EOVERFLOW);
       return 0;
-- 
1.7.6.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]