diff options
| author | Paul Eggert | 2011-06-22 23:45:38 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-06-22 23:45:38 -0700 |
| commit | 90532f02fdde568772852dc53be37d36855ef391 (patch) | |
| tree | 0ce49359c0970cb49861779ca44b8686c9ebeca7 /src | |
| parent | 6d84508d181fec22ef538b5a6ba7e2072d1de8e7 (diff) | |
| download | emacs-90532f02fdde568772852dc53be37d36855ef391.tar.gz emacs-90532f02fdde568772852dc53be37d36855ef391.zip | |
* 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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 4 | ||||
| -rw-r--r-- | src/minibuf.c | 14 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index c3eaaa4ff2d..1be34fdbfe2 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,9 @@ | |||
| 1 | 2011-06-23 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2011-06-23 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | * minibuf.c (read_minibuf_noninteractive): Use ptrdiff_t, not int, | ||
| 4 | for sizes. Check for string overflow more accurately. | ||
| 5 | Simplify newline removal at end; this suppresses a GCC 4.6.0 warning. | ||
| 6 | |||
| 3 | * macros.c: Integer and buffer overflow fixes. | 7 | * macros.c: Integer and buffer overflow fixes. |
| 4 | * keyboard.h (struct keyboard.kbd_macro_bufsize): | 8 | * keyboard.h (struct keyboard.kbd_macro_bufsize): |
| 5 | * macros.c (Fstart_kbd_macro, store_kbd_macro_char): | 9 | * macros.c (Fstart_kbd_macro, store_kbd_macro_char): |
diff --git a/src/minibuf.c b/src/minibuf.c index ca2f22df9ed..2b5e94ad356 100644 --- a/src/minibuf.c +++ b/src/minibuf.c | |||
| @@ -237,7 +237,7 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, | |||
| 237 | Lisp_Object defalt, | 237 | Lisp_Object defalt, |
| 238 | int allow_props, int inherit_input_method) | 238 | int allow_props, int inherit_input_method) |
| 239 | { | 239 | { |
| 240 | size_t size, len; | 240 | ptrdiff_t size, len; |
| 241 | char *line, *s; | 241 | char *line, *s; |
| 242 | Lisp_Object val; | 242 | Lisp_Object val; |
| 243 | 243 | ||
| @@ -247,12 +247,12 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, | |||
| 247 | val = Qnil; | 247 | val = Qnil; |
| 248 | size = 100; | 248 | size = 100; |
| 249 | len = 0; | 249 | len = 0; |
| 250 | line = (char *) xmalloc (size * sizeof *line); | 250 | line = (char *) xmalloc (size); |
| 251 | while ((s = fgets (line + len, size - len, stdin)) != NULL | 251 | while ((s = fgets (line + len, size - len, stdin)) != NULL |
| 252 | && (len = strlen (line), | 252 | && (len = strlen (line), |
| 253 | len == size - 1 && line[len - 1] != '\n')) | 253 | len == size - 1 && line[len - 1] != '\n')) |
| 254 | { | 254 | { |
| 255 | if ((size_t) -1 / 2 < size) | 255 | if (STRING_BYTES_BOUND / 2 < size) |
| 256 | memory_full (SIZE_MAX); | 256 | memory_full (SIZE_MAX); |
| 257 | size *= 2; | 257 | size *= 2; |
| 258 | line = (char *) xrealloc (line, size); | 258 | line = (char *) xrealloc (line, size); |
| @@ -260,11 +260,9 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, | |||
| 260 | 260 | ||
| 261 | if (s) | 261 | if (s) |
| 262 | { | 262 | { |
| 263 | len = strlen (line); | 263 | char *nl = strchr (line, '\n'); |
| 264 | 264 | if (nl) | |
| 265 | if (len > 0 && line[len - 1] == '\n') | 265 | *nl = '\0'; |
| 266 | line[--len] = '\0'; | ||
| 267 | |||
| 268 | val = build_string (line); | 266 | val = build_string (line); |
| 269 | xfree (line); | 267 | xfree (line); |
| 270 | } | 268 | } |