mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-04 22:50:59 -08:00
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.
This commit is contained in:
parent
b904a238a5
commit
c63e7f1bf6
7 changed files with 10 additions and 43 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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."
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue