]> code.delx.au - gnu-emacs/commitdiff
Simplify overflow check via INT_SUBTRACT_WRAPV
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 8 Jun 2016 07:35:11 +0000 (00:35 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 8 Jun 2016 07:36:18 +0000 (00:36 -0700)
* src/editfns.c (check_tm_member): Simplify integer overflow check.

src/editfns.c

index 6b0996d65eb8dbd40838d0157d4c0f47cc2de3c3..81c30d30d6220538eaf849b08ecad7880efb115c 100644 (file)
@@ -2176,17 +2176,16 @@ usage: (decode-time &optional TIME ZONE)  */)
 }
 
 /* Return OBJ - OFFSET, checking that OBJ is a valid fixnum and that
-   the result is representable as an int.  Assume OFFSET is small and
-   nonnegative.  */
+   the result is representable as an int.  */
 static int
 check_tm_member (Lisp_Object obj, int offset)
 {
-  EMACS_INT n;
   CHECK_NUMBER (obj);
-  n = XINT (obj);
-  if (! (INT_MIN + offset <= n && n - offset <= INT_MAX))
+  EMACS_INT n = XINT (obj);
+  int result;
+  if (INT_SUBTRACT_WRAPV (n, offset, &result))
     time_overflow ();
-  return n - offset;
+  return result;
 }
 
 DEFUN ("encode-time", Fencode_time, Sencode_time, 6, MANY, 0,