Comment 2 for bug 1028026

Revision history for this message
nixie (onixie) wrote :

The type error happens in function GET-INTERNAL-REAL-TIME

The value of 'now' variable is declared as unsigned-byte (which according to CLHS I think this is appropriate),
but when calculating its new value, the result from subtracting seconds might be negative one. (if setting the system time to the past).

I create a patch of this fix.
Thanks for the review and advice. :)

From 84a1161018bec29e50bca2806fdc35be93fe8249 Mon Sep 17 00:00:00 2001
From: Nixie <email address hidden>
Date: Fri, 27 Jul 2012 07:11:11 +0800
Subject: [PATCH] Rejuvenate the internal real time in case we return to the past

Fixes lp#1028026
---
 src/code/unix.lisp | 18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/code/unix.lisp b/src/code/unix.lisp
index 7a1a628..fbc679a 100644
--- a/src/code/unix.lisp
+++ b/src/code/unix.lisp
@@ -1174,13 +1174,17 @@ the UNIX epoch (January 1st 1970.)"
     ;; --MG
     (defun get-internal-real-time ()
       (multiple-value-bind (sec msec) (system-real-time-values)
- (unless (and (= msec c-msec) (= sec c-sec))
- (setf now (+ (* (- sec e-sec)
- sb!xc:internal-time-units-per-second)
- (- msec e-msec))
- c-msec msec
- c-sec sec))
- now)))
+ (if (or (< sec e-sec)
+ (and (= sec e-sec) (< msec e-msec)))
+ (progn (reinit-internal-real-time)
+ (setf now 0))
+ (unless (and (= msec c-msec) (= sec c-sec))
+ (setf now (+ (* (- sec e-sec)
+ sb!xc:internal-time-units-per-second)
+ (- msec e-msec))
+ c-msec msec
+ c-sec sec)))
+ now)))

   (defun system-internal-run-time ()
     (multiple-value-bind (ignore utime-sec utime-usec stime-sec stime-usec)
--
1.7.3.4