diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2015-11-07 23:52:17 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2015-11-07 23:52:57 -0800 |
commit | 8a8613bcf4227dfe46a694b761e9575bdf6ca2ce (patch) | |
tree | 01d9d994b9caacc831342ef1b32e033844fc06a6 /src/macros.c | |
parent | 6ea4ff5a362a150fb9e22eff1d8f2b87d017b7a4 (diff) | |
download | emacs-8a8613bcf4227dfe46a694b761e9575bdf6ca2ce.tar.gz |
Prefer xpalloc to doubling buffers by hand
* src/lread.c (grow_read_buffer): New function, which uses xpalloc.
(read1): Use it for simplicity.
* src/macros.c (store_kbd_macro_char):
* src/minibuf.c (read_minibuf_noninteractive):
* src/term.c (encode_terminal_code):
* src/xrdb.c (magic_db):
Prefer xpalloc to growing buffers by hand.
This doesn’t fix any bugs, but simplifies the code a bit.
Diffstat (limited to 'src/macros.c')
-rw-r--r-- | src/macros.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/macros.c b/src/macros.c index d963838069b..7c6ab2efc30 100644 --- a/src/macros.c +++ b/src/macros.c @@ -184,16 +184,11 @@ store_kbd_macro_char (Lisp_Object c) { if (kb->kbd_macro_ptr - kb->kbd_macro_buffer == kb->kbd_macro_bufsize) { - ptrdiff_t ptr_offset, end_offset, nbytes; - - ptr_offset = kb->kbd_macro_ptr - kb->kbd_macro_buffer; - end_offset = kb->kbd_macro_end - kb->kbd_macro_buffer; - if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *kb->kbd_macro_buffer / 2 - < kb->kbd_macro_bufsize) - memory_full (SIZE_MAX); - nbytes = kb->kbd_macro_bufsize * (2 * sizeof *kb->kbd_macro_buffer); - kb->kbd_macro_buffer = xrealloc (kb->kbd_macro_buffer, nbytes); - kb->kbd_macro_bufsize *= 2; + ptrdiff_t ptr_offset = kb->kbd_macro_ptr - kb->kbd_macro_buffer; + ptrdiff_t end_offset = kb->kbd_macro_end - kb->kbd_macro_buffer; + kb->kbd_macro_buffer = xpalloc (kb->kbd_macro_buffer, + &kb->kbd_macro_bufsize, + 1, -1, sizeof *kb->kbd_macro_buffer); kb->kbd_macro_ptr = kb->kbd_macro_buffer + ptr_offset; kb->kbd_macro_end = kb->kbd_macro_buffer + end_offset; } |