diff options
| author | Mattias EngdegÄrd | 2019-12-29 13:51:48 +0100 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2019-12-29 13:55:25 +0100 |
| commit | aa0c679f484347d20ab6f7c0f75f32f5e360cb89 (patch) | |
| tree | 1471501c2d1effaa28cf933cf52681d635a41fc5 | |
| parent | d6922db49dea33ac2bca8b33d24763cc7b2e4cd7 (diff) | |
| download | emacs-aa0c679f484347d20ab6f7c0f75f32f5e360cb89.tar.gz emacs-aa0c679f484347d20ab6f7c0f75f32f5e360cb89.zip | |
Avoid unbounded growth of cl-random-state components (bug#38753)
* lisp/emacs-lisp/cl-extra.el (cl-random):
Perform the modulo 2**23 operation before updating the state instead
of after. The result is always the same, but it prevents the state
from growing into arbitrary large bignums.
Patch from Christopher Wellons.
| -rw-r--r-- | lisp/emacs-lisp/cl-extra.el | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el index 7e9d8fe870b..2e0b37c14de 100644 --- a/lisp/emacs-lisp/cl-extra.el +++ b/lisp/emacs-lisp/cl-extra.el | |||
| @@ -469,7 +469,7 @@ Optional second arg STATE is a random-state object." | |||
| 469 | (while (< (setq i (1+ i)) 200) (cl-random 2 state)))) | 469 | (while (< (setq i (1+ i)) 200) (cl-random 2 state)))) |
| 470 | (let* ((i (cl-callf (lambda (x) (% (1+ x) 55)) (cl--random-state-i state))) | 470 | (let* ((i (cl-callf (lambda (x) (% (1+ x) 55)) (cl--random-state-i state))) |
| 471 | (j (cl-callf (lambda (x) (% (1+ x) 55)) (cl--random-state-j state))) | 471 | (j (cl-callf (lambda (x) (% (1+ x) 55)) (cl--random-state-j state))) |
| 472 | (n (logand 8388607 (aset vec i (- (aref vec i) (aref vec j)))))) | 472 | (n (aset vec i (logand 8388607 (- (aref vec i) (aref vec j)))))) |
| 473 | (if (integerp lim) | 473 | (if (integerp lim) |
| 474 | (if (<= lim 512) (% n lim) | 474 | (if (<= lim 512) (% n lim) |
| 475 | (if (> lim 8388607) (setq n (+ (ash n 9) (cl-random 512 state)))) | 475 | (if (> lim 8388607) (setq n (+ (ash n 9) (cl-random 512 state)))) |