diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2018-08-22 20:45:47 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2018-08-22 20:46:08 -0700 |
commit | a4a3c92e9de59bd0251f36326375cce898919edc (patch) | |
tree | cbc9d41f826266a3545c9c537929294b18d87108 /lisp/arc-mode.el | |
parent | ee641b87cf220250ba89f219fb47a4406a05deb7 (diff) | |
download | emacs-a4a3c92e9de59bd0251f36326375cce898919edc.tar.gz emacs-a4a3c92e9de59bd0251f36326375cce898919edc.tar.bz2 emacs-a4a3c92e9de59bd0251f36326375cce898919edc.zip |
Prune most-positive-fixnum from Lisp source
I looked through all instances of most-negative-fixnum
and most-positive-fixnum in the Lisp source code, and
when it was easy I removed assumptions that integers
fit in fixnums. The remaining instances are either
nontrivial to fix, or are inherent to the algorithm.
* lisp/arc-mode.el (archive-l-e): Do not convert to float,
since we have bignums now. All uses changed.
* lisp/calc/calc.el (math-bignum):
Don’t special-case most-negative-fixnum.
* lisp/calendar/parse-time.el (parse-time-string):
* lisp/emacs-lisp/edebug.el (edebug-read-special):
* lisp/emacs-lisp/package.el (package--remove-hidden):
* lisp/gnus/nnfolder.el (nnfolder-read-folder):
* lisp/international/mule-util.el (filepos-to-bufferpos--dos):
* lisp/menu-bar.el (menu-bar-update-buffers):
* lisp/net/rcirc.el (rcirc-handler-317):
* lisp/org/org-agenda.el (org-cmp-ts):
* lisp/window.el (window--resize-child-windows):
Avoid arbitrary limit to most-positive-fixnum or to
most-negative-fixnum.
* lisp/calendar/time-date.el (days-to-time):
* lisp/erc/erc-dcc.el (erc-unpack-int):
Don’t worry about integer overflow.
* lisp/cedet/semantic/wisent/comp.el (wisent-BITS-PER-WORD):
* lisp/gnus/message.el (message-unique-id):
* lisp/org/org-footnote.el (org-footnote-new):
Simplify.
* lisp/erc/erc-dcc.el (erc-most-positive-int-bytes)
(erc-most-positive-int-msb): Remove; no longer needed.
* lisp/net/imap.el (imap-string-to-integer): Remove; unused.
* lisp/org/org-element.el (org-element--cache-generate-key):
Document fixnum limitation.
Diffstat (limited to 'lisp/arc-mode.el')
-rw-r--r-- | lisp/arc-mode.el | 70 |
1 files changed, 22 insertions, 48 deletions
diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el index e45c6004b9a..50048c0cb39 100644 --- a/lisp/arc-mode.el +++ b/lisp/arc-mode.el @@ -531,12 +531,10 @@ Each descriptor is a vector of the form (defsubst archive-name (suffix) (intern (concat "archive-" (symbol-name archive-subtype) "-" suffix))) -(defun archive-l-e (str &optional len float) +(defun archive-l-e (str &optional len) "Convert little endian string/vector STR to integer. Alternatively, STR may be a buffer position in the current buffer -in which case a second argument, length LEN, should be supplied. -FLOAT, if non-nil, means generate and return a float instead of an integer -\(use this for numbers that can overflow the Emacs integer)." +in which case a second argument, length LEN, should be supplied." (if (stringp str) (setq len (length str)) (setq str (buffer-substring str (+ str len)))) @@ -545,7 +543,7 @@ FLOAT, if non-nil, means generate and return a float instead of an integer (i 0)) (while (< i len) (setq i (1+ i) - result (+ (if float (* result 256.0) (ash result 8)) + result (+ (ash result 8) (aref str (- len i))))) result)) @@ -1501,14 +1499,13 @@ This doesn't recover lost files, it just undoes changes in the buffer itself." (fnlen (or (string-match "\0" namefld) 13)) (efnname (decode-coding-string (substring namefld 0 fnlen) archive-file-name-coding-system)) - ;; Convert to float to avoid overflow for very large files. - (csize (archive-l-e (+ p 15) 4 'float)) + (csize (archive-l-e (+ p 15) 4)) (moddate (archive-l-e (+ p 19) 2)) (modtime (archive-l-e (+ p 21) 2)) - (ucsize (archive-l-e (+ p 25) 4 'float)) + (ucsize (archive-l-e (+ p 25) 4)) (fiddle (string= efnname (upcase efnname))) (ifnname (if fiddle (downcase efnname) efnname)) - (text (format " %8.0f %-11s %-8s %s" + (text (format " %8d %-11s %-8s %s" ucsize (archive-dosdate moddate) (archive-dostime modtime) @@ -1521,11 +1518,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself." visual) files (cons (vector efnname ifnname fiddle nil (1- p)) files) - ;; p needs to stay an integer, since we use it in char-after - ;; above. Passing through `round' limits the compressed size - ;; to most-positive-fixnum, but if the compressed size exceeds - ;; that, we cannot visit the archive anyway. - p (+ p 29 (round csize))))) + p (+ p 29 csize)))) (goto-char (point-min)) (let ((dash (concat "- -------- ----------- -------- " (make-string maxlen ?-) @@ -1534,7 +1527,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself." dash) (archive-summarize-files (nreverse visual)) (insert dash - (format " %8.0f %d file%s" + (format " %8d %d file%s" totalsize (length files) (if (= 1 (length files)) "" "s")) @@ -1567,10 +1560,9 @@ This doesn't recover lost files, it just undoes changes in the buffer itself." (while (progn (goto-char p) ;beginning of a base header. (looking-at "\\(.\\|\n\\)\\(.\\|\n\\)-l[hz][0-9ds]-")) (let* ((hsize (byte-after p)) ;size of the base header (level 0 and 1) - ;; Convert to float to avoid overflow for very large files. - (csize (archive-l-e (+ p 7) 4 'float)) ;size of a compressed file to follow (level 0 and 2), + (csize (archive-l-e (+ p 7) 4)) ;size of a compressed file to follow (level 0 and 2), ;size of extended headers + the compressed file to follow (level 1). - (ucsize (archive-l-e (+ p 11) 4 'float)) ;size of an uncompressed file. + (ucsize (archive-l-e (+ p 11) 4)) ;size of an uncompressed file. (time1 (archive-l-e (+ p 15) 2)) ;date/time (MSDOS format in level 0, 1 headers (time2 (archive-l-e (+ p 17) 2)) ;and UNIX format in level 2 header.) (hdrlvl (byte-after (+ p 20))) ;header level @@ -1660,12 +1652,12 @@ This doesn't recover lost files, it just undoes changes in the buffer itself." (archive-unixtime time1 time2) (archive-dostime time1))) (setq text (if archive-alternate-display - (format " %8.0f %5S %5S %s" + (format " %8d %5S %5S %s" ucsize (or uid "?") (or gid "?") ifnname) - (format " %10s %8.0f %-11s %-8s %s" + (format " %10s %8d %-11s %-8s %s" modestr ucsize moddate @@ -1680,13 +1672,9 @@ This doesn't recover lost files, it just undoes changes in the buffer itself." files (cons (vector prname ifnname fiddle mode (1- p)) files)) (cond ((= hdrlvl 1) - ;; p needs to stay an integer, since we use it in goto-char - ;; above. Passing through `round' limits the compressed size - ;; to most-positive-fixnum, but if the compressed size exceeds - ;; that, we cannot visit the archive anyway. - (setq p (+ p hsize 2 (round csize)))) + (setq p (+ p hsize 2 csize))) ((or (= hdrlvl 2) (= hdrlvl 0)) - (setq p (+ p thsize 2 (round csize))))) + (setq p (+ p thsize 2 csize)))) )) (goto-char (point-min)) (let ((dash (concat (if archive-alternate-display @@ -1824,32 +1812,21 @@ This doesn't recover lost files, it just undoes changes in the buffer itself." ;; ;; First, find the Zip64 end-of-central-directory locator. (search-backward "PK\006\007") - ;; Pay attention: the offset of Zip64 end-of-central-directory - ;; is a 64-bit field, so it could overflow the Emacs integer - ;; even on a 64-bit host, let alone 32-bit one. But since we've - ;; already read the zip file into a buffer, and this is a byte - ;; offset into the file we've read, it must be short enough, so - ;; such an overflow can never happen, and we can safely read - ;; these 8 bytes into an Emacs integer. Moreover, on host with - ;; 32-bit Emacs integer we can only read 4 bytes, since they are - ;; stored in little-endian byte order. - (setq emacs-int-has-32bits (<= most-positive-fixnum #x1fffffff)) (setq p (+ (point-min) - (archive-l-e (+ (point) 8) (if emacs-int-has-32bits 4 8)))) + (archive-l-e (+ (point) 8) 8))) (goto-char p) ;; We should be at Zip64 end-of-central-directory record now. (or (string= "PK\006\006" (buffer-substring p (+ p 4))) (error "Unrecognized ZIP file format")) ;; Offset to central directory: - (setq p (archive-l-e (+ p 48) (if emacs-int-has-32bits 4 8)))) + (setq p (archive-l-e (+ p 48) 8))) (setq p (+ p (point-min))) (while (string= "PK\001\002" (buffer-substring p (+ p 4))) (let* ((creator (byte-after (+ p 5))) ;; (method (archive-l-e (+ p 10) 2)) (modtime (archive-l-e (+ p 12) 2)) (moddate (archive-l-e (+ p 14) 2)) - ;; Convert to float to avoid overflow for very large files. - (ucsize (archive-l-e (+ p 24) 4 'float)) + (ucsize (archive-l-e (+ p 24) 4)) (fnlen (archive-l-e (+ p 28) 2)) (exlen (archive-l-e (+ p 30) 2)) (fclen (archive-l-e (+ p 32) 2)) @@ -1874,7 +1851,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself." (string= (upcase efnname) efnname))) (ifnname (if fiddle (downcase efnname) efnname)) (width (string-width ifnname)) - (text (format " %10s %8.0f %-11s %-8s %s" + (text (format " %10s %8d %-11s %-8s %s" modestr ucsize (archive-dosdate moddate) @@ -1900,7 +1877,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself." dash) (archive-summarize-files (nreverse visual)) (insert dash - (format " %8.0f %d file%s" + (format " %8d %d file%s" totalsize (length files) (if (= 1 (length files)) "" "s")) @@ -1971,8 +1948,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself." (let* ((next (1+ (archive-l-e (+ p 6) 4))) (moddate (archive-l-e (+ p 14) 2)) (modtime (archive-l-e (+ p 16) 2)) - ;; Convert to float to avoid overflow for very large files. - (ucsize (archive-l-e (+ p 20) 4 'float)) + (ucsize (archive-l-e (+ p 20) 4)) (namefld (buffer-substring (+ p 38) (+ p 38 13))) (dirtype (byte-after (+ p 4))) (lfnlen (if (= dirtype 2) (byte-after (+ p 56)) 0)) @@ -1995,7 +1971,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself." (fiddle (and (= lfnlen 0) (string= efnname (upcase efnname)))) (ifnname (if fiddle (downcase efnname) efnname)) (width (string-width ifnname)) - (text (format " %8.0f %-11s %-8s %s" + (text (format " %8d %-11s %-8s %s" ucsize (archive-dosdate moddate) (archive-dostime modtime) @@ -2017,7 +1993,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself." dash) (archive-summarize-files (nreverse visual)) (insert dash - (format " %8.0f %d file%s" + (format " %8d %d file%s" totalsize (length files) (if (= 1 (length files)) "" "s")) @@ -2211,8 +2187,6 @@ This doesn't recover lost files, it just undoes changes in the buffer itself." (while (looking-at archive-ar-file-header-re) (let ((name (match-string 1)) extname - ;; Emacs will automatically use float here because those - ;; timestamps don't fit in our ints. (time (string-to-number (match-string 2))) (user (match-string 3)) (group (match-string 4)) |