diff options
| author | Paul Eggert | 2018-03-29 10:16:29 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-03-29 11:03:07 -0700 |
| commit | 6b3d01dad415230ad0bd0d01a05351d7a8b0e8c3 (patch) | |
| tree | d49bf4520d6afc830aa9d016be3d57349b251c4f /test/src | |
| parent | 3409fe0362c52127c52f854a7300f4dde4b8fffe (diff) | |
| download | emacs-6b3d01dad415230ad0bd0d01a05351d7a8b0e8c3.tar.gz emacs-6b3d01dad415230ad0bd0d01a05351d7a8b0e8c3.zip | |
Lisp reader now checks for integer overflow
* doc/lispref/numbers.texi (Integer Basics), etc/NEWS:
Document this.
* src/lisp.h (S2N_IGNORE_TRAILING, S2N_OVERFLOW_TO_FLOAT):
New constants.
* src/lread.c (string_to_number): Change trailing bool arg to
integer argument with flags, to support S2N_OVERFLOW_TO_FLOAT.
All uses changed.
* test/src/editfns-tests.el (read-large-integer): New test.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/editfns-tests.el | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el index 6e1f730166d..442ad089375 100644 --- a/test/src/editfns-tests.el +++ b/test/src/editfns-tests.el | |||
| @@ -142,27 +142,41 @@ | |||
| 142 | (should (string-equal (format "%#05X" #x10) "0X010")) | 142 | (should (string-equal (format "%#05X" #x10) "0X010")) |
| 143 | (should (string-equal (format "%#04x" 0) "0000"))) | 143 | (should (string-equal (format "%#04x" 0) "0000"))) |
| 144 | 144 | ||
| 145 | ;;; Test Bug#30408. | 145 | |
| 146 | ;;; Tests for Bug#30408. | ||
| 147 | |||
| 146 | (ert-deftest format-%d-large-float () | 148 | (ert-deftest format-%d-large-float () |
| 147 | (should (string-equal (format "%d" 18446744073709551616.0) | 149 | (should (string-equal (format "%d" 18446744073709551616.0) |
| 148 | "18446744073709551616")) | 150 | "18446744073709551616")) |
| 149 | (should (string-equal (format "%d" -18446744073709551616.0) | 151 | (should (string-equal (format "%d" -18446744073709551616.0) |
| 150 | "-18446744073709551616"))) | 152 | "-18446744073709551616"))) |
| 151 | 153 | ||
| 152 | ;;; Another test for Bug#30408. | ||
| 153 | ;;; Perhaps Emacs will be improved someday to return the correct | 154 | ;;; Perhaps Emacs will be improved someday to return the correct |
| 154 | ;;; answer for positive numbers instead of overflowing; in | 155 | ;;; answer for positive numbers instead of overflowing; in |
| 155 | ;;; that case this test will need to be changed. In the meantime make | 156 | ;;; that case these tests will need to be changed. In the meantime make |
| 156 | ;;; sure Emacs is reporting the overflow correctly. | 157 | ;;; sure Emacs is reporting the overflow correctly. |
| 157 | (ert-deftest format-%x-large-float () | 158 | (ert-deftest format-%x-large-float () |
| 158 | (should-error (format "%x" 18446744073709551616.0) | 159 | (should-error (format "%x" 18446744073709551616.0) |
| 159 | :type 'overflow-error)) | 160 | :type 'overflow-error)) |
| 161 | (ert-deftest read-large-integer () | ||
| 162 | (should-error (read (format "%d0" most-negative-fixnum)) | ||
| 163 | :type 'overflow-error) | ||
| 164 | (should-error (read (format "%+d" (* -8.0 most-negative-fixnum))) | ||
| 165 | :type 'overflow-error) | ||
| 166 | (should-error (read (substring (format "%d" most-negative-fixnum) 1)) | ||
| 167 | :type 'overflow-error) | ||
| 168 | (should-error (read (format "#x%x" most-negative-fixnum)) | ||
| 169 | :type 'overflow-error) | ||
| 170 | (should-error (read (format "#o%o" most-negative-fixnum)) | ||
| 171 | :type 'overflow-error) | ||
| 172 | (should-error (read (format "#32rG%x" most-positive-fixnum)) | ||
| 173 | :type 'overflow-error)) | ||
| 160 | 174 | ||
| 161 | ;;; Another test for Bug#30408. | ||
| 162 | (ert-deftest format-%o-invalid-float () | 175 | (ert-deftest format-%o-invalid-float () |
| 163 | (should-error (format "%o" -1e-37) | 176 | (should-error (format "%o" -1e-37) |
| 164 | :type 'overflow-error)) | 177 | :type 'overflow-error)) |
| 165 | 178 | ||
| 179 | |||
| 166 | ;;; Check format-time-string with various TZ settings. | 180 | ;;; Check format-time-string with various TZ settings. |
| 167 | ;;; Use only POSIX-compatible TZ values, since the tests should work | 181 | ;;; Use only POSIX-compatible TZ values, since the tests should work |
| 168 | ;;; even if tzdb is not in use. | 182 | ;;; even if tzdb is not in use. |