[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master c63e7f1: Remove no-longer-needed integer overflow c
From: |
Paul Eggert |
Subject: |
[Emacs-diffs] master c63e7f1: Remove no-longer-needed integer overflow code |
Date: |
Mon, 22 Jul 2019 19:36:55 -0400 (EDT) |
branch: master
commit c63e7f1bf6151d4bb5fde01890c69cdd515e2df3
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>
Remove no-longer-needed integer overflow code
* lisp/calculator.el (calculator-number-to-string):
Use truncate, not calculator-truncate, since integer
overflow cannot occur here.
* lisp/calendar/cal-persia.el (calendar-persian-year-from-absolute):
* lisp/gnus/gnus-agent.el (gnus-agent-read-article-number):
* lisp/gnus/nnmaildir.el (nnmaildir--group-maxnum)
(nnmaildir--new-number):
* lisp/scroll-bar.el (scroll-bar-scale):
* lisp/simple.el (beginning-of-buffer, end-of-buffer):
Simplify, now that integer overflow cannot occur.
---
lisp/calculator.el | 2 +-
lisp/calendar/cal-persia.el | 8 +-------
lisp/files.el | 4 ++--
lisp/gnus/gnus-agent.el | 15 +--------------
lisp/gnus/nnmaildir.el | 6 +-----
lisp/scroll-bar.el | 4 +---
lisp/simple.el | 14 +++-----------
7 files changed, 10 insertions(+), 43 deletions(-)
diff --git a/lisp/calculator.el b/lisp/calculator.el
index eec7aff..281151c 100644
--- a/lisp/calculator.el
+++ b/lisp/calculator.el
@@ -1054,7 +1054,7 @@ the `left' or `right' when one of the standard modes is
used."
;; print with radix -- for binary, convert the octal number
(let* ((fmt (if (eq calculator-output-radix 'hex) "%x" "%o"))
(str (if calculator-2s-complement num (abs num)))
- (str (format fmt (calculator-truncate str)))
+ (str (format fmt (truncate str)))
(bins '((?0 "000") (?1 "001") (?2 "010") (?3 "011")
(?4 "100") (?5 "101") (?6 "110") (?7 "111")))
(str (if (not (eq calculator-output-radix 'bin)) str
diff --git a/lisp/calendar/cal-persia.el b/lisp/calendar/cal-persia.el
index 897208f..59fe52a 100644
--- a/lisp/calendar/cal-persia.el
+++ b/lisp/calendar/cal-persia.el
@@ -100,13 +100,7 @@ Gregorian date Sunday, December 31, 1 BC."
(d2 ; prior days not in n2820 or n768
(mod d1 280506))
(n1 ; years not in n2820 or n768
- ;; Want:
- ;; (floor (+ (* 2820 d2) (* 2820 366)) 1029983))
- ;; but that causes overflow, so use the following.
- ;; Use 366 as the divisor because (2820*366 mod 1029983) is small.
- (let ((a (floor d2 366))
- (b (mod d2 366)))
- (+ 1 a (floor (+ (* 2137 a) (* 2820 b) 2137) 1029983))))
+ (floor (* 2820 (+ d2 366)) 1029983))
(year (+ (* 2820 n2820) ; complete 2820 year cycles
(* 768 n768) ; complete 768 year cycles
;; Remaining years.
diff --git a/lisp/files.el b/lisp/files.el
index 70865eb..81ca948 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -4959,8 +4959,8 @@ Uses `backup-directory-alist' in the same way as
(list (make-backup-file-name fn))
(cons (format "%s.~%d~" basic-name (1+ high-water-mark))
(if (and (> number-to-delete 0)
- ;; Delete nothing if there is overflow
- ;; in the number of versions to keep.
+ ;; Delete nothing if kept-new-versions and
+ ;; kept-old-versions combine to an outlandish value.
(>= (+ kept-new-versions kept-old-versions -1) 0))
(mapcar (lambda (n)
(format "%s.~%d~" basic-name n))
diff --git a/lisp/gnus/gnus-agent.el b/lisp/gnus/gnus-agent.el
index a09b436..40d0d24 100644
--- a/lisp/gnus/gnus-agent.el
+++ b/lisp/gnus/gnus-agent.el
@@ -1909,21 +1909,8 @@ article numbers will be returned."
(defsubst gnus-agent-read-article-number ()
"Reads the article number at point. Returns nil when a valid article number
can not be read."
- ;; It is unfortunate but the read function quietly overflows
- ;; integer. As a result, I have to use string operations to test
- ;; for overflow BEFORE calling read.
(when (looking-at "[0-9]+\t")
- (let ((len (- (match-end 0) (match-beginning 0))))
- (cond ((< len 9)
- (read (current-buffer)))
- ((= len 9)
- ;; Many 9 digit base-10 numbers can be represented in a 27-bit int
- ;; Back convert from int to string to ensure that this is one of
them.
- (let* ((str1 (buffer-substring (match-beginning 0) (1- (match-end
0))))
- (num (read (current-buffer)))
- (str2 (int-to-string num)))
- (when (equal str1 str2)
- num)))))))
+ (read (current-buffer))))
(defsubst gnus-agent-copy-nov-line (article)
"Copy the indicated ARTICLE from the overview buffer to the nntp server
buffer."
diff --git a/lisp/gnus/nnmaildir.el b/lisp/gnus/nnmaildir.el
index 3becee3..246f52c 100644
--- a/lisp/gnus/nnmaildir.el
+++ b/lisp/gnus/nnmaildir.el
@@ -322,8 +322,6 @@ This variable is set by `nnmaildir-request-article'.")
(setq ino-opened (file-attribute-inode-number attr)
nlink (file-attribute-link-number attr)
number-linked (+ number-opened nlink))
- (if (or (< nlink 1) (< number-linked nlink))
- (signal 'error '("Arithmetic overflow")))
(setq attr (file-attributes
(concat dir (number-to-string number-linked))))
(or attr (throw 'return (1- number-linked)))
@@ -395,9 +393,7 @@ This variable is set by `nnmaildir-request-article'.")
(let* ((attr (file-attributes path-open))
(nlink (file-attribute-link-number attr)))
(setq ino-open (file-attribute-inode-number attr)
- number-link (+ number-open nlink))
- (if (or (< nlink 1) (< number-link nlink))
- (signal 'error '("Arithmetic overflow"))))
+ number-link (+ number-open nlink)))
(if (= number-link previous-number-link)
;; We've already tried this number, in the previous loop iteration,
;; and failed.
diff --git a/lisp/scroll-bar.el b/lisp/scroll-bar.el
index dc0df7a..61fa754 100644
--- a/lisp/scroll-bar.el
+++ b/lisp/scroll-bar.el
@@ -49,9 +49,7 @@ from a scroll bar event, then (scroll-bar-scale SCROLL-BAR-POS
\(buffer-size)) is the position in the current buffer corresponding to
that scroll bar position."
;; We multiply before we divide to maintain precision.
- ;; We use floating point because the product of a large buffer size
- ;; with a large scroll bar portion can easily overflow a lisp int.
- (truncate (/ (* (float (car num-denom)) whole) (cdr num-denom))))
+ (truncate (* (car num-denom) whole) (cdr num-denom)))
(defun scroll-bar-columns (side)
"Return the width, measured in columns, of the vertical scrollbar on SIDE.
diff --git a/lisp/simple.el b/lisp/simple.el
index 00265ec..e33709e 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1037,12 +1037,8 @@ is supplied, or Transient Mark mode is enabled and the
mark is active."
(push-mark))
(let ((size (- (point-max) (point-min))))
(goto-char (if (and arg (not (consp arg)))
- (+ (point-min)
- (if (> size 10000)
- ;; Avoid overflow for large buffer sizes!
- (* (prefix-numeric-value arg)
- (/ size 10))
- (/ (+ 10 (* size (prefix-numeric-value arg))) 10)))
+ (+ (point-min) 1
+ (/ (* size (prefix-numeric-value arg)) 10))
(point-min))))
(if (and arg (not (consp arg))) (forward-line 1)))
@@ -1060,11 +1056,7 @@ is supplied, or Transient Mark mode is enabled and the
mark is active."
(let ((size (- (point-max) (point-min))))
(goto-char (if (and arg (not (consp arg)))
(- (point-max)
- (if (> size 10000)
- ;; Avoid overflow for large buffer sizes!
- (* (prefix-numeric-value arg)
- (/ size 10))
- (/ (* size (prefix-numeric-value arg)) 10)))
+ (/ (* size (prefix-numeric-value arg)) 10))
(point-max))))
;; If we went to a place in the middle of the buffer,
;; adjust it to the beginning of a line.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master c63e7f1: Remove no-longer-needed integer overflow code,
Paul Eggert <=