diff options
| author | Paul Eggert | 2018-08-21 13:44:03 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-08-21 13:44:32 -0700 |
| commit | f18af6cd5cb7dbbf7420ec2d3efed4e202c4f0dd (patch) | |
| tree | 5f42e48e12a0ec77bd5cd5f32255a534635e89bf /lisp/mail | |
| parent | 81e7eef8224c8a99a207b7a7b9dae1d598392ef7 (diff) | |
| download | emacs-f18af6cd5cb7dbbf7420ec2d3efed4e202c4f0dd.tar.gz emacs-f18af6cd5cb7dbbf7420ec2d3efed4e202c4f0dd.zip | |
Audit use of lsh and fix glitches
I audited use of lsh in the Lisp source code, and fixed the
glitches that I found. While I was at it, I replaced uses of lsh
with ash when either will do. Replacement is OK when either
argument is known to be nonnegative, or when only the low-order
bits of the result matter, and is a (minor) win since ash is a bit
more solid than lsh nowadays, and is a bit faster.
* lisp/calc/calc-ext.el (math-check-fixnum):
Prefer most-positive-fixnum to (lsh -1 -1).
* lisp/vc/vc-hg.el (vc-hg-state-fast): When testing fixnum width,
prefer (zerop (ash most-positive-fixnum -32)) to (zerop (lsh -1
32)) (Bug#32485#11).
* lisp/emacs-lisp/bytecomp.el (byte-compile-lapcode):
Tighten sanity-check for bytecode overflow, by checking that the
result of (ash pc -8) is nonnegative. Formerly this check was not
needed since lsh was used and the number overflowed differently.
* lisp/net/dns.el (dns-write): Fix some obvious sign typos in
shift counts. Evidently this part of the code has never been
exercised.
* lisp/progmodes/hideif.el (hif-shiftleft, hif-shiftright):
* lisp/term/common-win.el (x-setup-function-keys):
Simplify.
* admin/unidata/unidata-gen.el, admin/unidata/uvs.el:
* doc/lispref/keymaps.texi, doc/lispref/syntax.texi:
* doc/misc/calc.texi, doc/misc/cl.texi, etc/NEWS.19:
* lisp/arc-mode.el, lisp/calc/calc-bin.el, lisp/calc/calc-comb.el:
* lisp/calc/calc-ext.el, lisp/calc/calc-math.el:
* lisp/cedet/semantic/wisent/comp.el, lisp/composite.el:
* lisp/disp-table.el, lisp/dos-fns.el, lisp/edmacro.el:
* lisp/emacs-lisp/bindat.el, lisp/emacs-lisp/byte-opt.el:
* lisp/emacs-lisp/bytecomp.el, lisp/emacs-lisp/cl-extra.el:
* lisp/erc/erc-dcc.el, lisp/facemenu.el, lisp/gnus/message.el:
* lisp/gnus/nndoc.el, lisp/gnus/nnmaildir.el, lisp/image.el:
* lisp/international/ccl.el, lisp/international/fontset.el:
* lisp/international/mule-cmds.el, lisp/international/mule.el:
* lisp/json.el, lisp/mail/binhex.el, lisp/mail/rmail.el:
* lisp/mail/uudecode.el, lisp/md4.el, lisp/net/dns.el:
* lisp/net/ntlm.el, lisp/net/sasl.el, lisp/net/socks.el:
* lisp/net/tramp.el, lisp/obsolete/levents.el:
* lisp/obsolete/pgg-parse.el, lisp/org/org.el:
* lisp/org/ox-publish.el, lisp/progmodes/cc-defs.el:
* lisp/progmodes/ebnf2ps.el, lisp/progmodes/hideif.el:
* lisp/ps-bdf.el, lisp/ps-print.el, lisp/simple.el:
* lisp/tar-mode.el, lisp/term/common-win.el:
* lisp/term/tty-colors.el, lisp/term/xterm.el, lisp/vc/vc-git.el:
* lisp/vc/vc-hg.el, lisp/x-dnd.el, test/src/data-tests.el:
Prefer ash to lsh when either will do.
Diffstat (limited to 'lisp/mail')
| -rw-r--r-- | lisp/mail/binhex.el | 20 | ||||
| -rw-r--r-- | lisp/mail/rmail.el | 2 | ||||
| -rw-r--r-- | lisp/mail/uudecode.el | 12 |
3 files changed, 17 insertions, 17 deletions
diff --git a/lisp/mail/binhex.el b/lisp/mail/binhex.el index 299fc0b2341..fa2ea3d8471 100644 --- a/lisp/mail/binhex.el +++ b/lisp/mail/binhex.el | |||
| @@ -136,9 +136,9 @@ input and write the converted data to its standard output." | |||
| 136 | (defun binhex-update-crc (crc char &optional count) | 136 | (defun binhex-update-crc (crc char &optional count) |
| 137 | (if (null count) (setq count 1)) | 137 | (if (null count) (setq count 1)) |
| 138 | (while (> count 0) | 138 | (while (> count 0) |
| 139 | (setq crc (logxor (logand (lsh crc 8) 65280) | 139 | (setq crc (logxor (logand (ash crc 8) 65280) |
| 140 | (aref binhex-crc-table | 140 | (aref binhex-crc-table |
| 141 | (logxor (logand (lsh crc -8) 255) | 141 | (logxor (logand (ash crc -8) 255) |
| 142 | char))) | 142 | char))) |
| 143 | count (1- count))) | 143 | count (1- count))) |
| 144 | crc) | 144 | crc) |
| @@ -156,14 +156,14 @@ input and write the converted data to its standard output." | |||
| 156 | (defun binhex-string-big-endian (string) | 156 | (defun binhex-string-big-endian (string) |
| 157 | (let ((ret 0) (i 0) (len (length string))) | 157 | (let ((ret 0) (i 0) (len (length string))) |
| 158 | (while (< i len) | 158 | (while (< i len) |
| 159 | (setq ret (+ (lsh ret 8) (binhex-char-int (aref string i))) | 159 | (setq ret (+ (ash ret 8) (binhex-char-int (aref string i))) |
| 160 | i (1+ i))) | 160 | i (1+ i))) |
| 161 | ret)) | 161 | ret)) |
| 162 | 162 | ||
| 163 | (defun binhex-string-little-endian (string) | 163 | (defun binhex-string-little-endian (string) |
| 164 | (let ((ret 0) (i 0) (shift 0) (len (length string))) | 164 | (let ((ret 0) (i 0) (shift 0) (len (length string))) |
| 165 | (while (< i len) | 165 | (while (< i len) |
| 166 | (setq ret (+ ret (lsh (binhex-char-int (aref string i)) shift)) | 166 | (setq ret (+ ret (ash (binhex-char-int (aref string i)) shift)) |
| 167 | i (1+ i) | 167 | i (1+ i) |
| 168 | shift (+ shift 8))) | 168 | shift (+ shift 8))) |
| 169 | ret)) | 169 | ret)) |
| @@ -239,13 +239,13 @@ If HEADER-ONLY is non-nil only decode header and return filename." | |||
| 239 | counter (1+ counter) | 239 | counter (1+ counter) |
| 240 | inputpos (1+ inputpos)) | 240 | inputpos (1+ inputpos)) |
| 241 | (cond ((= counter 4) | 241 | (cond ((= counter 4) |
| 242 | (binhex-push-char (lsh bits -16) nil work-buffer) | 242 | (binhex-push-char (ash bits -16) nil work-buffer) |
| 243 | (binhex-push-char (logand (lsh bits -8) 255) nil | 243 | (binhex-push-char (logand (ash bits -8) 255) nil |
| 244 | work-buffer) | 244 | work-buffer) |
| 245 | (binhex-push-char (logand bits 255) nil | 245 | (binhex-push-char (logand bits 255) nil |
| 246 | work-buffer) | 246 | work-buffer) |
| 247 | (setq bits 0 counter 0)) | 247 | (setq bits 0 counter 0)) |
| 248 | (t (setq bits (lsh bits 6))))) | 248 | (t (setq bits (ash bits 6))))) |
| 249 | (if (null file-name-length) | 249 | (if (null file-name-length) |
| 250 | (with-current-buffer work-buffer | 250 | (with-current-buffer work-buffer |
| 251 | (setq file-name-length (char-after (point-min)) | 251 | (setq file-name-length (char-after (point-min)) |
| @@ -261,12 +261,12 @@ If HEADER-ONLY is non-nil only decode header and return filename." | |||
| 261 | (setq tmp (and tmp (not (eq inputpos end))))) | 261 | (setq tmp (and tmp (not (eq inputpos end))))) |
| 262 | (cond | 262 | (cond |
| 263 | ((= counter 3) | 263 | ((= counter 3) |
| 264 | (binhex-push-char (logand (lsh bits -16) 255) nil | 264 | (binhex-push-char (logand (ash bits -16) 255) nil |
| 265 | work-buffer) | 265 | work-buffer) |
| 266 | (binhex-push-char (logand (lsh bits -8) 255) nil | 266 | (binhex-push-char (logand (ash bits -8) 255) nil |
| 267 | work-buffer)) | 267 | work-buffer)) |
| 268 | ((= counter 2) | 268 | ((= counter 2) |
| 269 | (binhex-push-char (logand (lsh bits -10) 255) nil | 269 | (binhex-push-char (logand (ash bits -10) 255) nil |
| 270 | work-buffer)))) | 270 | work-buffer)))) |
| 271 | (if header-only nil | 271 | (if header-only nil |
| 272 | (binhex-verify-crc work-buffer | 272 | (binhex-verify-crc work-buffer |
diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el index 12a58b293d0..9416d049028 100644 --- a/lisp/mail/rmail.el +++ b/lisp/mail/rmail.el | |||
| @@ -4515,7 +4515,7 @@ encoded string (and the same mask) will decode the string." | |||
| 4515 | (if (= curmask 0) | 4515 | (if (= curmask 0) |
| 4516 | (setq curmask mask)) | 4516 | (setq curmask mask)) |
| 4517 | (setq charmask (% curmask 256)) | 4517 | (setq charmask (% curmask 256)) |
| 4518 | (setq curmask (lsh curmask -8)) | 4518 | (setq curmask (ash curmask -8)) |
| 4519 | (aset string-vector i (logxor charmask (aref string-vector i))) | 4519 | (aset string-vector i (logxor charmask (aref string-vector i))) |
| 4520 | (setq i (1+ i))) | 4520 | (setq i (1+ i))) |
| 4521 | (concat string-vector))) | 4521 | (concat string-vector))) |
diff --git a/lisp/mail/uudecode.el b/lisp/mail/uudecode.el index 0cdceca6ff5..b8f74e3a839 100644 --- a/lisp/mail/uudecode.el +++ b/lisp/mail/uudecode.el | |||
| @@ -171,12 +171,12 @@ If FILE-NAME is non-nil, save the result to FILE-NAME." | |||
| 171 | (cond ((= counter 4) | 171 | (cond ((= counter 4) |
| 172 | (setq result (cons | 172 | (setq result (cons |
| 173 | (concat | 173 | (concat |
| 174 | (char-to-string (lsh bits -16)) | 174 | (char-to-string (ash bits -16)) |
| 175 | (char-to-string (logand (lsh bits -8) 255)) | 175 | (char-to-string (logand (ash bits -8) 255)) |
| 176 | (char-to-string (logand bits 255))) | 176 | (char-to-string (logand bits 255))) |
| 177 | result)) | 177 | result)) |
| 178 | (setq bits 0 counter 0)) | 178 | (setq bits 0 counter 0)) |
| 179 | (t (setq bits (lsh bits 6))))))) | 179 | (t (setq bits (ash bits 6))))))) |
| 180 | (cond | 180 | (cond |
| 181 | (done) | 181 | (done) |
| 182 | ((> 0 remain) | 182 | ((> 0 remain) |
| @@ -188,12 +188,12 @@ If FILE-NAME is non-nil, save the result to FILE-NAME." | |||
| 188 | ((= counter 3) | 188 | ((= counter 3) |
| 189 | (setq result (cons | 189 | (setq result (cons |
| 190 | (concat | 190 | (concat |
| 191 | (char-to-string (logand (lsh bits -16) 255)) | 191 | (char-to-string (logand (ash bits -16) 255)) |
| 192 | (char-to-string (logand (lsh bits -8) 255))) | 192 | (char-to-string (logand (ash bits -8) 255))) |
| 193 | result))) | 193 | result))) |
| 194 | ((= counter 2) | 194 | ((= counter 2) |
| 195 | (setq result (cons | 195 | (setq result (cons |
| 196 | (char-to-string (logand (lsh bits -10) 255)) | 196 | (char-to-string (logand (ash bits -10) 255)) |
| 197 | result)))) | 197 | result)))) |
| 198 | (skip-chars-forward non-data-chars end)) | 198 | (skip-chars-forward non-data-chars end)) |
| 199 | (if file-name | 199 | (if file-name |