bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#11825: 24.1.50; float-time no longer accepts negative time values


From: Paul Eggert
Subject: bug#11825: 24.1.50; float-time no longer accepts negative time values
Date: Sun, 08 Jul 2012 16:03:39 -0700
User-agent: Mozilla/5.0 (X11; Linux i686; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

On 07/08/2012 02:00 AM, Andreas Schwab wrote:
> A difference between two timestamps is always signed.

No, not if A is an absolute time, and B is a (nonnegative) offset.
The result is an absolute time, and is unsigned if A was unsigned.
For example:

         EMACS_GET_TIME (t);
         EMACS_SUB_TIME (old, t, EMACS_TIME_FROM_DOUBLE (delay));

This is a common way that EMACS_SUB_TIME is used in Emacs.

On 07/08/2012 08:32 AM, Eli Zaretskii wrote:> E.g., to express something like
>
>   T1 = T2 + T3 - T4
>
> instead of a simple
>
>   t1 = timespec_add (t2, timespec_sub (t3, t4));

That doesn't suffice even if struct timespec uses a signed
time_t -- if overflow occurred in the timespec_sub, the
result might be incorrect.

There is no simple solution here that does not involve
complicating the API.  Luckily, Emacs never needs to compute
expressions like the above, so the problem doesn't need to
be addressed right now.

> this should be prominently explained in systime.h.

OK, sure, I pushed this:

--- src/systime.h       2012-07-07 01:57:42 +0000
+++ src/systime.h       2012-07-08 22:57:42 +0000
@@ -80,7 +80,8 @@
 #define EMACS_GET_TIME(time)               gettime (&(time))

 /* Put into DEST the result of adding SRC1 to SRC2, or of subtracting
-   SRC2 from SRC1.  On overflow, store an extremal value.  */
+   SRC2 from SRC1.  On overflow, store an extremal value: ergo, if
+   time_t is unsigned, return 0 if the true answer would be negative.  */
 #define EMACS_ADD_TIME(dest, src1, src2) ((dest) = timespec_add (src1, src2))
 #define EMACS_SUB_TIME(dest, src1, src2) ((dest) = timespec_sub (src1, src2))






reply via email to

[Prev in Thread] Current Thread [Next in Thread]