summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtchang%redhat.com <devnull@localhost>2006-01-09 22:51:04 +0000
committerwtchang%redhat.com <devnull@localhost>2006-01-09 22:51:04 +0000
commit3526d01d1784e975d1418dd4567b4ee899a1d6f0 (patch)
treecdb8f907700acaadc4bb760d6519b01b49953021
parentc8cd1dee875ef23f99f182382e1e8c31d4707243 (diff)
downloadnspr-hg-3526d01d1784e975d1418dd4567b4ee899a1d6f0.tar.gz
Bugzilla Bug 322422: fixed a negative integer division truncation direction
error, which resulted in a negative PRTime with fractional seconds being converted to PRExplodedTime off by one second. Thanks to Aleksey Sanin <aleksey@aleksey.com> for reporting and investigating the bug and reviewing the patch. r=aleskey. Tag: NSPRPUB_PRE_4_2_CLIENT_BRANCH
-rw-r--r--pr/src/misc/prtime.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/pr/src/misc/prtime.c b/pr/src/misc/prtime.c
index b0c0fec0..67aa2332 100644
--- a/pr/src/misc/prtime.c
+++ b/pr/src/misc/prtime.c
@@ -617,6 +617,7 @@ PR_LocalTimeParameters(const PRExplodedTime *gmt)
time_t secs;
PRTime secs64;
PRInt64 usecPerSec;
+ PRInt64 usecPerSec_1;
PRInt64 maxInt32;
PRInt64 minInt32;
PRInt32 dayOffset;
@@ -663,7 +664,16 @@ PR_LocalTimeParameters(const PRExplodedTime *gmt)
secs64 = PR_ImplodeTime(gmt); /* This is still in microseconds */
LL_I2L(usecPerSec, PR_USEC_PER_SEC);
- LL_DIV(secs64, secs64, usecPerSec); /* Convert to seconds */
+ LL_I2L(usecPerSec_1, PR_USEC_PER_SEC - 1);
+ /* Convert to seconds, truncating down (3.1 -> 3 and -3.1 -> -4) */
+ if (LL_GE_ZERO(secs64)) {
+ LL_DIV(secs64, secs64, usecPerSec);
+ } else {
+ LL_NEG(secs64, secs64);
+ LL_ADD(secs64, secs64, usecPerSec_1);
+ LL_DIV(secs64, secs64, usecPerSec);
+ LL_NEG(secs64, secs64);
+ }
LL_I2L(maxInt32, PR_INT32_MAX);
LL_I2L(minInt32, PR_INT32_MIN);
if (LL_CMP(secs64, >, maxInt32) || LL_CMP(secs64, <, minInt32)) {