Commit 90532f02 authored by Paul Eggert's avatar Paul Eggert

* minibuf.c (read_minibuf_noninteractive): Use ptrdiff_t, not int,

for sizes.  Check for string overflow more accurately.
Simplify newline removal at end; this suppresses a GCC 4.6.0 warning.
parent 6d84508d
2011-06-23 Paul Eggert <eggert@cs.ucla.edu> 2011-06-23 Paul Eggert <eggert@cs.ucla.edu>
* minibuf.c (read_minibuf_noninteractive): Use ptrdiff_t, not int,
for sizes. Check for string overflow more accurately.
Simplify newline removal at end; this suppresses a GCC 4.6.0 warning.
* macros.c: Integer and buffer overflow fixes. * macros.c: Integer and buffer overflow fixes.
* keyboard.h (struct keyboard.kbd_macro_bufsize): * keyboard.h (struct keyboard.kbd_macro_bufsize):
* macros.c (Fstart_kbd_macro, store_kbd_macro_char): * macros.c (Fstart_kbd_macro, store_kbd_macro_char):
......
...@@ -237,7 +237,7 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, ...@@ -237,7 +237,7 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial,
Lisp_Object defalt, Lisp_Object defalt,
int allow_props, int inherit_input_method) int allow_props, int inherit_input_method)
{ {
size_t size, len; ptrdiff_t size, len;
char *line, *s; char *line, *s;
Lisp_Object val; Lisp_Object val;
...@@ -247,12 +247,12 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, ...@@ -247,12 +247,12 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial,
val = Qnil; val = Qnil;
size = 100; size = 100;
len = 0; len = 0;
line = (char *) xmalloc (size * sizeof *line); line = (char *) xmalloc (size);
while ((s = fgets (line + len, size - len, stdin)) != NULL while ((s = fgets (line + len, size - len, stdin)) != NULL
&& (len = strlen (line), && (len = strlen (line),
len == size - 1 && line[len - 1] != '\n')) len == size - 1 && line[len - 1] != '\n'))
{ {
if ((size_t) -1 / 2 < size) if (STRING_BYTES_BOUND / 2 < size)
memory_full (SIZE_MAX); memory_full (SIZE_MAX);
size *= 2; size *= 2;
line = (char *) xrealloc (line, size); line = (char *) xrealloc (line, size);
...@@ -260,11 +260,9 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, ...@@ -260,11 +260,9 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial,
if (s) if (s)
{ {
len = strlen (line); char *nl = strchr (line, '\n');
if (nl)
if (len > 0 && line[len - 1] == '\n') *nl = '\0';
line[--len] = '\0';
val = build_string (line); val = build_string (line);
xfree (line); xfree (line);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment