summaryrefslogtreecommitdiff
path: root/src/macros.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/macros.c')
-rw-r--r--src/macros.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/macros.c b/src/macros.c
index acba125edc5..c73986abd34 100644
--- a/src/macros.c
+++ b/src/macros.c
@@ -80,28 +80,24 @@ macro before appending to it. */)
}
else
{
- ptrdiff_t i;
- EMACS_INT len;
+ const ptrdiff_t incr = 30;
+ ptrdiff_t i, len;
bool cvt;
/* Check the type of last-kbd-macro in case Lisp code changed it. */
- CHECK_VECTOR_OR_STRING (KVAR (current_kboard, Vlast_kbd_macro));
+ len = CHECK_VECTOR_OR_STRING (KVAR (current_kboard, Vlast_kbd_macro));
- len = XINT (Flength (KVAR (current_kboard, Vlast_kbd_macro)));
+ if (INT_ADD_OVERFLOW (len, incr))
+ memory_full (SIZE_MAX);
/* Copy last-kbd-macro into the buffer, in case the Lisp code
has put another macro there. */
- if (current_kboard->kbd_macro_bufsize < len + 30)
- {
- if (PTRDIFF_MAX < MOST_POSITIVE_FIXNUM + 30
- && PTRDIFF_MAX < len + 30)
- memory_full (SIZE_MAX);
- current_kboard->kbd_macro_buffer =
- xpalloc (current_kboard->kbd_macro_buffer,
- &current_kboard->kbd_macro_bufsize,
- len + 30 - current_kboard->kbd_macro_bufsize, -1,
- sizeof *current_kboard->kbd_macro_buffer);
- }
+ if (current_kboard->kbd_macro_bufsize < len + incr)
+ current_kboard->kbd_macro_buffer =
+ xpalloc (current_kboard->kbd_macro_buffer,
+ &current_kboard->kbd_macro_bufsize,
+ len + incr - current_kboard->kbd_macro_bufsize, -1,
+ sizeof *current_kboard->kbd_macro_buffer);
/* Must convert meta modifier when copying string to vector. */
cvt = STRINGP (KVAR (current_kboard, Vlast_kbd_macro));