diff options
| author | Paul Eggert | 2019-07-22 16:26:27 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-07-22 16:36:50 -0700 |
| commit | c63e7f1bf6151d4bb5fde01890c69cdd515e2df3 (patch) | |
| tree | db9958355d3b0a85c9a621ba4f0f07eca391dc2d | |
| parent | b904a238a5ab759a4d0d8c9ee5c48199febd8f62 (diff) | |
| download | emacs-c63e7f1bf6151d4bb5fde01890c69cdd515e2df3.tar.gz emacs-c63e7f1bf6151d4bb5fde01890c69cdd515e2df3.zip | |
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.
| -rw-r--r-- | lisp/calculator.el | 2 | ||||
| -rw-r--r-- | lisp/calendar/cal-persia.el | 8 | ||||
| -rw-r--r-- | lisp/files.el | 4 | ||||
| -rw-r--r-- | lisp/gnus/gnus-agent.el | 15 | ||||
| -rw-r--r-- | lisp/gnus/nnmaildir.el | 6 | ||||
| -rw-r--r-- | lisp/scroll-bar.el | 4 | ||||
| -rw-r--r-- | lisp/simple.el | 14 |
7 files changed, 10 insertions, 43 deletions
diff --git a/lisp/calculator.el b/lisp/calculator.el index eec7aff5878..281151c7c25 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." | |||
| 1054 | ;; print with radix -- for binary, convert the octal number | 1054 | ;; print with radix -- for binary, convert the octal number |
| 1055 | (let* ((fmt (if (eq calculator-output-radix 'hex) "%x" "%o")) | 1055 | (let* ((fmt (if (eq calculator-output-radix 'hex) "%x" "%o")) |
| 1056 | (str (if calculator-2s-complement num (abs num))) | 1056 | (str (if calculator-2s-complement num (abs num))) |
| 1057 | (str (format fmt (calculator-truncate str))) | 1057 | (str (format fmt (truncate str))) |
| 1058 | (bins '((?0 "000") (?1 "001") (?2 "010") (?3 "011") | 1058 | (bins '((?0 "000") (?1 "001") (?2 "010") (?3 "011") |
| 1059 | (?4 "100") (?5 "101") (?6 "110") (?7 "111"))) | 1059 | (?4 "100") (?5 "101") (?6 "110") (?7 "111"))) |
| 1060 | (str (if (not (eq calculator-output-radix 'bin)) str | 1060 | (str (if (not (eq calculator-output-radix 'bin)) str |
diff --git a/lisp/calendar/cal-persia.el b/lisp/calendar/cal-persia.el index 897208fd2b4..59fe52a592a 100644 --- a/lisp/calendar/cal-persia.el +++ b/lisp/calendar/cal-persia.el | |||
| @@ -100,13 +100,7 @@ Gregorian date Sunday, December 31, 1 BC." | |||
| 100 | (d2 ; prior days not in n2820 or n768 | 100 | (d2 ; prior days not in n2820 or n768 |
| 101 | (mod d1 280506)) | 101 | (mod d1 280506)) |
| 102 | (n1 ; years not in n2820 or n768 | 102 | (n1 ; years not in n2820 or n768 |
| 103 | ;; Want: | 103 | (floor (* 2820 (+ d2 366)) 1029983)) |
| 104 | ;; (floor (+ (* 2820 d2) (* 2820 366)) 1029983)) | ||
| 105 | ;; but that causes overflow, so use the following. | ||
| 106 | ;; Use 366 as the divisor because (2820*366 mod 1029983) is small. | ||
| 107 | (let ((a (floor d2 366)) | ||
| 108 | (b (mod d2 366))) | ||
| 109 | (+ 1 a (floor (+ (* 2137 a) (* 2820 b) 2137) 1029983)))) | ||
| 110 | (year (+ (* 2820 n2820) ; complete 2820 year cycles | 104 | (year (+ (* 2820 n2820) ; complete 2820 year cycles |
| 111 | (* 768 n768) ; complete 768 year cycles | 105 | (* 768 n768) ; complete 768 year cycles |
| 112 | ;; Remaining years. | 106 | ;; Remaining years. |
diff --git a/lisp/files.el b/lisp/files.el index 70865ebcdf1..81ca948bd2d 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -4959,8 +4959,8 @@ Uses `backup-directory-alist' in the same way as | |||
| 4959 | (list (make-backup-file-name fn)) | 4959 | (list (make-backup-file-name fn)) |
| 4960 | (cons (format "%s.~%d~" basic-name (1+ high-water-mark)) | 4960 | (cons (format "%s.~%d~" basic-name (1+ high-water-mark)) |
| 4961 | (if (and (> number-to-delete 0) | 4961 | (if (and (> number-to-delete 0) |
| 4962 | ;; Delete nothing if there is overflow | 4962 | ;; Delete nothing if kept-new-versions and |
| 4963 | ;; in the number of versions to keep. | 4963 | ;; kept-old-versions combine to an outlandish value. |
| 4964 | (>= (+ kept-new-versions kept-old-versions -1) 0)) | 4964 | (>= (+ kept-new-versions kept-old-versions -1) 0)) |
| 4965 | (mapcar (lambda (n) | 4965 | (mapcar (lambda (n) |
| 4966 | (format "%s.~%d~" basic-name n)) | 4966 | (format "%s.~%d~" basic-name n)) |
diff --git a/lisp/gnus/gnus-agent.el b/lisp/gnus/gnus-agent.el index a09b4368893..40d0d246056 100644 --- a/lisp/gnus/gnus-agent.el +++ b/lisp/gnus/gnus-agent.el | |||
| @@ -1909,21 +1909,8 @@ article numbers will be returned." | |||
| 1909 | (defsubst gnus-agent-read-article-number () | 1909 | (defsubst gnus-agent-read-article-number () |
| 1910 | "Reads the article number at point. Returns nil when a valid article number can not be read." | 1910 | "Reads the article number at point. Returns nil when a valid article number can not be read." |
| 1911 | 1911 | ||
| 1912 | ;; It is unfortunate but the read function quietly overflows | ||
| 1913 | ;; integer. As a result, I have to use string operations to test | ||
| 1914 | ;; for overflow BEFORE calling read. | ||
| 1915 | (when (looking-at "[0-9]+\t") | 1912 | (when (looking-at "[0-9]+\t") |
| 1916 | (let ((len (- (match-end 0) (match-beginning 0)))) | 1913 | (read (current-buffer)))) |
| 1917 | (cond ((< len 9) | ||
| 1918 | (read (current-buffer))) | ||
| 1919 | ((= len 9) | ||
| 1920 | ;; Many 9 digit base-10 numbers can be represented in a 27-bit int | ||
| 1921 | ;; Back convert from int to string to ensure that this is one of them. | ||
| 1922 | (let* ((str1 (buffer-substring (match-beginning 0) (1- (match-end 0)))) | ||
| 1923 | (num (read (current-buffer))) | ||
| 1924 | (str2 (int-to-string num))) | ||
| 1925 | (when (equal str1 str2) | ||
| 1926 | num))))))) | ||
| 1927 | 1914 | ||
| 1928 | (defsubst gnus-agent-copy-nov-line (article) | 1915 | (defsubst gnus-agent-copy-nov-line (article) |
| 1929 | "Copy the indicated ARTICLE from the overview buffer to the nntp server buffer." | 1916 | "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 3becee35112..246f52c8d2b 100644 --- a/lisp/gnus/nnmaildir.el +++ b/lisp/gnus/nnmaildir.el | |||
| @@ -322,8 +322,6 @@ This variable is set by `nnmaildir-request-article'.") | |||
| 322 | (setq ino-opened (file-attribute-inode-number attr) | 322 | (setq ino-opened (file-attribute-inode-number attr) |
| 323 | nlink (file-attribute-link-number attr) | 323 | nlink (file-attribute-link-number attr) |
| 324 | number-linked (+ number-opened nlink)) | 324 | number-linked (+ number-opened nlink)) |
| 325 | (if (or (< nlink 1) (< number-linked nlink)) | ||
| 326 | (signal 'error '("Arithmetic overflow"))) | ||
| 327 | (setq attr (file-attributes | 325 | (setq attr (file-attributes |
| 328 | (concat dir (number-to-string number-linked)))) | 326 | (concat dir (number-to-string number-linked)))) |
| 329 | (or attr (throw 'return (1- number-linked))) | 327 | (or attr (throw 'return (1- number-linked))) |
| @@ -395,9 +393,7 @@ This variable is set by `nnmaildir-request-article'.") | |||
| 395 | (let* ((attr (file-attributes path-open)) | 393 | (let* ((attr (file-attributes path-open)) |
| 396 | (nlink (file-attribute-link-number attr))) | 394 | (nlink (file-attribute-link-number attr))) |
| 397 | (setq ino-open (file-attribute-inode-number attr) | 395 | (setq ino-open (file-attribute-inode-number attr) |
| 398 | number-link (+ number-open nlink)) | 396 | number-link (+ number-open nlink))) |
| 399 | (if (or (< nlink 1) (< number-link nlink)) | ||
| 400 | (signal 'error '("Arithmetic overflow")))) | ||
| 401 | (if (= number-link previous-number-link) | 397 | (if (= number-link previous-number-link) |
| 402 | ;; We've already tried this number, in the previous loop iteration, | 398 | ;; We've already tried this number, in the previous loop iteration, |
| 403 | ;; and failed. | 399 | ;; and failed. |
diff --git a/lisp/scroll-bar.el b/lisp/scroll-bar.el index dc0df7ab3fe..61fa754e390 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 | |||
| 49 | \(buffer-size)) is the position in the current buffer corresponding to | 49 | \(buffer-size)) is the position in the current buffer corresponding to |
| 50 | that scroll bar position." | 50 | that scroll bar position." |
| 51 | ;; We multiply before we divide to maintain precision. | 51 | ;; We multiply before we divide to maintain precision. |
| 52 | ;; We use floating point because the product of a large buffer size | 52 | (truncate (* (car num-denom) whole) (cdr num-denom))) |
| 53 | ;; with a large scroll bar portion can easily overflow a lisp int. | ||
| 54 | (truncate (/ (* (float (car num-denom)) whole) (cdr num-denom)))) | ||
| 55 | 53 | ||
| 56 | (defun scroll-bar-columns (side) | 54 | (defun scroll-bar-columns (side) |
| 57 | "Return the width, measured in columns, of the vertical scrollbar on SIDE. | 55 | "Return the width, measured in columns, of the vertical scrollbar on SIDE. |
diff --git a/lisp/simple.el b/lisp/simple.el index 00265ece71e..e33709e8ad4 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." | |||
| 1037 | (push-mark)) | 1037 | (push-mark)) |
| 1038 | (let ((size (- (point-max) (point-min)))) | 1038 | (let ((size (- (point-max) (point-min)))) |
| 1039 | (goto-char (if (and arg (not (consp arg))) | 1039 | (goto-char (if (and arg (not (consp arg))) |
| 1040 | (+ (point-min) | 1040 | (+ (point-min) 1 |
| 1041 | (if (> size 10000) | 1041 | (/ (* size (prefix-numeric-value arg)) 10)) |
| 1042 | ;; Avoid overflow for large buffer sizes! | ||
| 1043 | (* (prefix-numeric-value arg) | ||
| 1044 | (/ size 10)) | ||
| 1045 | (/ (+ 10 (* size (prefix-numeric-value arg))) 10))) | ||
| 1046 | (point-min)))) | 1042 | (point-min)))) |
| 1047 | (if (and arg (not (consp arg))) (forward-line 1))) | 1043 | (if (and arg (not (consp arg))) (forward-line 1))) |
| 1048 | 1044 | ||
| @@ -1060,11 +1056,7 @@ is supplied, or Transient Mark mode is enabled and the mark is active." | |||
| 1060 | (let ((size (- (point-max) (point-min)))) | 1056 | (let ((size (- (point-max) (point-min)))) |
| 1061 | (goto-char (if (and arg (not (consp arg))) | 1057 | (goto-char (if (and arg (not (consp arg))) |
| 1062 | (- (point-max) | 1058 | (- (point-max) |
| 1063 | (if (> size 10000) | 1059 | (/ (* size (prefix-numeric-value arg)) 10)) |
| 1064 | ;; Avoid overflow for large buffer sizes! | ||
| 1065 | (* (prefix-numeric-value arg) | ||
| 1066 | (/ size 10)) | ||
| 1067 | (/ (* size (prefix-numeric-value arg)) 10))) | ||
| 1068 | (point-max)))) | 1060 | (point-max)))) |
| 1069 | ;; If we went to a place in the middle of the buffer, | 1061 | ;; If we went to a place in the middle of the buffer, |
| 1070 | ;; adjust it to the beginning of a line. | 1062 | ;; adjust it to the beginning of a line. |