aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lread.c24
-rw-r--r--src/macros.c15
-rw-r--r--src/minibuf.c7
-rw-r--r--src/term.c8
-rw-r--r--src/xrdb.c8
5 files changed, 24 insertions, 38 deletions
diff --git a/src/lread.c b/src/lread.c
index 7c891f9954f..c4456f37f6d 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -2120,6 +2120,15 @@ read0 (Lisp_Object readcharfun)
2120static ptrdiff_t read_buffer_size; 2120static ptrdiff_t read_buffer_size;
2121static char *read_buffer; 2121static char *read_buffer;
2122 2122
2123/* Grow the read buffer by at least MAX_MULTIBYTE_LENGTH bytes. */
2124
2125static void
2126grow_read_buffer (void)
2127{
2128 read_buffer = xpalloc (read_buffer, &read_buffer_size,
2129 MAX_MULTIBYTE_LENGTH, -1, 1);
2130}
2131
2123/* Read a \-escape sequence, assuming we already read the `\'. 2132/* Read a \-escape sequence, assuming we already read the `\'.
2124 If the escape sequence forces unibyte, return eight-bit char. */ 2133 If the escape sequence forces unibyte, return eight-bit char. */
2125 2134
@@ -2985,10 +2994,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
2985 if (end - p < MAX_MULTIBYTE_LENGTH) 2994 if (end - p < MAX_MULTIBYTE_LENGTH)
2986 { 2995 {
2987 ptrdiff_t offset = p - read_buffer; 2996 ptrdiff_t offset = p - read_buffer;
2988 if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) 2997 grow_read_buffer ();
2989 memory_full (SIZE_MAX);
2990 read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
2991 read_buffer_size *= 2;
2992 p = read_buffer + offset; 2998 p = read_buffer + offset;
2993 end = read_buffer + read_buffer_size; 2999 end = read_buffer + read_buffer_size;
2994 } 3000 }
@@ -3119,10 +3125,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
3119 if (end - p < MAX_MULTIBYTE_LENGTH) 3125 if (end - p < MAX_MULTIBYTE_LENGTH)
3120 { 3126 {
3121 ptrdiff_t offset = p - read_buffer; 3127 ptrdiff_t offset = p - read_buffer;
3122 if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) 3128 grow_read_buffer ();
3123 memory_full (SIZE_MAX);
3124 read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
3125 read_buffer_size *= 2;
3126 p = read_buffer + offset; 3129 p = read_buffer + offset;
3127 end = read_buffer + read_buffer_size; 3130 end = read_buffer + read_buffer_size;
3128 } 3131 }
@@ -3149,10 +3152,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
3149 if (p == end) 3152 if (p == end)
3150 { 3153 {
3151 ptrdiff_t offset = p - read_buffer; 3154 ptrdiff_t offset = p - read_buffer;
3152 if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) 3155 grow_read_buffer ();
3153 memory_full (SIZE_MAX);
3154 read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
3155 read_buffer_size *= 2;
3156 p = read_buffer + offset; 3156 p = read_buffer + offset;
3157 end = read_buffer + read_buffer_size; 3157 end = read_buffer + read_buffer_size;
3158 } 3158 }
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)
184 { 184 {
185 if (kb->kbd_macro_ptr - kb->kbd_macro_buffer == kb->kbd_macro_bufsize) 185 if (kb->kbd_macro_ptr - kb->kbd_macro_buffer == kb->kbd_macro_bufsize)
186 { 186 {
187 ptrdiff_t ptr_offset, end_offset, nbytes; 187 ptrdiff_t ptr_offset = kb->kbd_macro_ptr - kb->kbd_macro_buffer;
188 188 ptrdiff_t end_offset = kb->kbd_macro_end - kb->kbd_macro_buffer;
189 ptr_offset = kb->kbd_macro_ptr - kb->kbd_macro_buffer; 189 kb->kbd_macro_buffer = xpalloc (kb->kbd_macro_buffer,
190 end_offset = kb->kbd_macro_end - kb->kbd_macro_buffer; 190 &kb->kbd_macro_bufsize,
191 if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *kb->kbd_macro_buffer / 2 191 1, -1, sizeof *kb->kbd_macro_buffer);
192 < kb->kbd_macro_bufsize)
193 memory_full (SIZE_MAX);
194 nbytes = kb->kbd_macro_bufsize * (2 * sizeof *kb->kbd_macro_buffer);
195 kb->kbd_macro_buffer = xrealloc (kb->kbd_macro_buffer, nbytes);
196 kb->kbd_macro_bufsize *= 2;
197 kb->kbd_macro_ptr = kb->kbd_macro_buffer + ptr_offset; 192 kb->kbd_macro_ptr = kb->kbd_macro_buffer + ptr_offset;
198 kb->kbd_macro_end = kb->kbd_macro_buffer + end_offset; 193 kb->kbd_macro_end = kb->kbd_macro_buffer + end_offset;
199 } 194 }
diff --git a/src/minibuf.c b/src/minibuf.c
index 31b69461bde..727a70b166f 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -229,12 +229,7 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial,
229 if (hide_char) 229 if (hide_char)
230 fprintf (stdout, "%c", hide_char); 230 fprintf (stdout, "%c", hide_char);
231 if (len == size) 231 if (len == size)
232 { 232 line = xpalloc (line, &size, 1, -1, sizeof *line);
233 if (STRING_BYTES_BOUND / 2 < size)
234 memory_full (SIZE_MAX);
235 size *= 2;
236 line = xrealloc (line, size);
237 }
238 line[len++] = c; 233 line[len++] = c;
239 } 234 }
240 } 235 }
diff --git a/src/term.c b/src/term.c
index 9b1e7cad4b2..245712ecfc4 100644
--- a/src/term.c
+++ b/src/term.c
@@ -537,10 +537,10 @@ encode_terminal_code (struct glyph *src, int src_len,
537 required = src_len; 537 required = src_len;
538 required *= MAX_MULTIBYTE_LENGTH; 538 required *= MAX_MULTIBYTE_LENGTH;
539 if (encode_terminal_src_size < required) 539 if (encode_terminal_src_size < required)
540 { 540 encode_terminal_src = xpalloc (encode_terminal_src,
541 encode_terminal_src = xrealloc (encode_terminal_src, required); 541 &encode_terminal_src_size,
542 encode_terminal_src_size = required; 542 required - encode_terminal_src_size,
543 } 543 -1, sizeof *encode_terminal_src);
544 544
545 charset_list = coding_charset_list (coding); 545 charset_list = coding_charset_list (coding);
546 546
diff --git a/src/xrdb.c b/src/xrdb.c
index ce6e7d21edb..10bc76986e6 100644
--- a/src/xrdb.c
+++ b/src/xrdb.c
@@ -177,12 +177,8 @@ magic_db (const char *string, ptrdiff_t string_len, const char *class,
177 177
178 /* Do we have room for this component followed by a '\0'? */ 178 /* Do we have room for this component followed by a '\0'? */
179 if (path_size - path_len <= next_len) 179 if (path_size - path_len <= next_len)
180 { 180 path = xpalloc (path, &path_size, path_len - path_size + next_len + 1,
181 if (min (PTRDIFF_MAX, SIZE_MAX) / 2 - 1 - path_len < next_len) 181 -1, sizeof *path);
182 memory_full (SIZE_MAX);
183 path_size = (path_len + next_len + 1) * 2;
184 path = xrealloc (path, path_size);
185 }
186 182
187 memcpy (path + path_len, next, next_len); 183 memcpy (path + path_len, next, next_len);
188 path_len += next_len; 184 path_len += next_len;