diff options
| author | Paul Eggert | 2015-11-08 22:47:01 -0800 |
|---|---|---|
| committer | Paul Eggert | 2015-11-08 22:48:28 -0800 |
| commit | 1087305574fd61256d66eb0c995f8bb74bd91afe (patch) | |
| tree | 9f0052e41a56c785575727931ff4abb8e7dfa7e0 /src/buffer.c | |
| parent | bcca6a2a028d05af3cb5b31a5a2c997f3f1f1d31 (diff) | |
| download | emacs-1087305574fd61256d66eb0c995f8bb74bd91afe.tar.gz emacs-1087305574fd61256d66eb0c995f8bb74bd91afe.zip | |
Use INT_ADD_WRAPV etc. to check integer overflow
* src/alloc.c (xnmalloc, xnrealloc, xpalloc, Fmake_string):
* src/buffer.c (record_overlay_string, overlay_strings):
* src/casefiddle.c (casify_object):
* src/ccl.c (Fccl_execute_on_string):
* src/character.c (char_width, c_string_width, lisp_string_width)
(count_size_as_multibyte, string_escape_byte8):
* src/coding.c (coding_alloc_by_realloc, produce_chars):
* src/data.c (arith_driver):
* src/dispnew.c (realloc_glyph_pool, init_display):
* src/editfns.c (styled_format):
* src/fns.c (Ffillarray):
* src/ftfont.c (ftfont_shape_by_flt):
* src/gnutls.c (gnutls_hex_string):
* src/gtkutil.c (get_utf8_string):
* src/image.c (x_to_xcolors, x_detect_edges, png_load_body):
* src/keymap.c (Fkey_description):
* src/lisp.h (SAFE_ALLOCA_LISP):
* src/term.c (encode_terminal_code):
* src/tparam.c (tparam1):
* src/xselect.c (x_property_data_to_lisp):
* src/xsmfns.c (smc_save_yourself_CB):
* src/xterm.c (x_term_init):
When checking for integer overflow, prefer INT_MULTIPLY_WRAPV to
more-complicated code involving division and/or
INT_MULTIPLY_OVERFLOW, and similarly for INT_ADD_WRAPV and
subtraction and/or INT_ADD_OVERFLOW.
* src/casefiddle.c (casify_object): Simplify multibyte size check.
* src/character.c: Remove some obsolete ‘#ifdef emacs’s.
* src/data.c (arith_driver): Also check for division overflow,
as that’s now possible given that the accumulator can now contain
any Emacs integer.
* src/lisp.h (lisp_word_count): Remove; no longer used.
Diffstat (limited to 'src/buffer.c')
| -rw-r--r-- | src/buffer.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/buffer.c b/src/buffer.c index c0179c7584e..ab91aaa4e81 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -3245,9 +3245,9 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str, | |||
| 3245 | else | 3245 | else |
| 3246 | nbytes = SBYTES (str); | 3246 | nbytes = SBYTES (str); |
| 3247 | 3247 | ||
| 3248 | if (INT_ADD_OVERFLOW (ssl->bytes, nbytes)) | 3248 | if (INT_ADD_WRAPV (ssl->bytes, nbytes, &nbytes)) |
| 3249 | memory_full (SIZE_MAX); | 3249 | memory_full (SIZE_MAX); |
| 3250 | ssl->bytes += nbytes; | 3250 | ssl->bytes = nbytes; |
| 3251 | 3251 | ||
| 3252 | if (STRINGP (str2)) | 3252 | if (STRINGP (str2)) |
| 3253 | { | 3253 | { |
| @@ -3259,9 +3259,9 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str, | |||
| 3259 | else | 3259 | else |
| 3260 | nbytes = SBYTES (str2); | 3260 | nbytes = SBYTES (str2); |
| 3261 | 3261 | ||
| 3262 | if (INT_ADD_OVERFLOW (ssl->bytes, nbytes)) | 3262 | if (INT_ADD_WRAPV (ssl->bytes, nbytes, &nbytes)) |
| 3263 | memory_full (SIZE_MAX); | 3263 | memory_full (SIZE_MAX); |
| 3264 | ssl->bytes += nbytes; | 3264 | ssl->bytes = nbytes; |
| 3265 | } | 3265 | } |
| 3266 | } | 3266 | } |
| 3267 | 3267 | ||
| @@ -3357,9 +3357,8 @@ overlay_strings (ptrdiff_t pos, struct window *w, unsigned char **pstr) | |||
| 3357 | unsigned char *p; | 3357 | unsigned char *p; |
| 3358 | ptrdiff_t total; | 3358 | ptrdiff_t total; |
| 3359 | 3359 | ||
| 3360 | if (INT_ADD_OVERFLOW (overlay_heads.bytes, overlay_tails.bytes)) | 3360 | if (INT_ADD_WRAPV (overlay_heads.bytes, overlay_tails.bytes, &total)) |
| 3361 | memory_full (SIZE_MAX); | 3361 | memory_full (SIZE_MAX); |
| 3362 | total = overlay_heads.bytes + overlay_tails.bytes; | ||
| 3363 | if (total > overlay_str_len) | 3362 | if (total > overlay_str_len) |
| 3364 | overlay_str_buf = xpalloc (overlay_str_buf, &overlay_str_len, | 3363 | overlay_str_buf = xpalloc (overlay_str_buf, &overlay_str_len, |
| 3365 | total - overlay_str_len, -1, 1); | 3364 | total - overlay_str_len, -1, 1); |