OSDN Git Service

Fix an infinite loop in time2sub.
authorDavid 'Digit' Turner <digit@google.com>
Thu, 10 Sep 2009 00:41:59 +0000 (17:41 -0700)
committerDavid 'Digit' Turner <digit@google.com>
Thu, 10 Sep 2009 00:45:00 +0000 (17:45 -0700)
commit2093d350be21ff086f9e145404877941b9a42c5c
tree7fcb6a68bb996c3c62d0dfdf54a08b8e50adb970
parentb4423ff7dfd8c97688cbf87ba8ce22f5b54fa89c
Fix an infinite loop in time2sub.

The problem is that time_t is signed, and the original code relied on the
fact that (X + c < X) in case of overflow for c >= 0. Unfortunately, this
condition is only guaranteed by the standard for unsigned arithmetic, and
the gcc 4.4.0 optimizer did completely remove the corresponding test from
the code. This resulted in a missing boundary check, and an infinite loop.

The problem is solved by testing explicitely for TIME_T_MIN and TIME_T_MAX
in the loop that uses this.

Also fix increment_overflow and long_increment_overflow which were buggy
for exactly the same reasons.

Note: a similar fix is needed for system/core/libcutils
libc/tzcode/localtime.c