From 2669cade3dcebf5d572bcd535cf21934cbc1633c Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 9 Mar 2016 18:25:00 +0000 Subject: [PATCH] Simplify saved_command_line handling There doesn't seem to be much point in trying to reuse this buffer. Prefer simplicity instead. (In case you're wondering whether this fixes an off-by-one: linelength is misnamed; it's really a size including terminating null char.) gdb/ChangeLog: 2016-03-09 Pedro Alves * event-top.c (command_line_handler): Use xfree + xstrdup instead of xrealloc + strcpy. * main.c (captured_main): Use xstrdup instead of xmalloc plus manual clear. * top.c (saved_command_line): Rewrite comment. (saved_command_line_size): Delete. (command_line_input): Use xfree + xstrdup instead of xrealloc + strcpy. * top.h (saved_command_line_size): Delete declaration. --- gdb/ChangeLog | 12 ++++++++++++ gdb/event-top.c | 9 ++------- gdb/main.c | 3 +-- gdb/top.c | 15 ++++----------- gdb/top.h | 1 - 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 881d231..bc2e99e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,17 @@ 2016-03-09 Pedro Alves + * event-top.c (command_line_handler): Use xfree + xstrdup instead + of xrealloc + strcpy. + * main.c (captured_main): Use xstrdup instead of xmalloc plus + manual clear. + * top.c (saved_command_line): Rewrite comment. + (saved_command_line_size): Delete. + (command_line_input): Use xfree + xstrdup instead of xrealloc + + strcpy. + * top.h (saved_command_line_size): Delete declaration. + +2016-03-09 Pedro Alves + * event-top.c: Include buffer.h. (gdb_readline_no_editing_callback): Use struct buffer instead of xrealloc. diff --git a/gdb/event-top.c b/gdb/event-top.c index 8857235..f112c52 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -650,13 +650,8 @@ command_line_handler (char *rl) /* Save into global buffer if appropriate. */ if (repeat) { - if (linelength > saved_command_line_size) - { - saved_command_line - = (char *) xrealloc (saved_command_line, linelength); - saved_command_line_size = linelength; - } - strcpy (saved_command_line, linebuffer); + xfree (saved_command_line); + saved_command_line = xstrdup (linebuffer); if (!more_to_come) { command_handler (saved_command_line); diff --git a/gdb/main.c b/gdb/main.c index a338b90..93ed98f 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -506,8 +506,7 @@ captured_main (void *data) ndir = 0; clear_quit_flag (); - saved_command_line = (char *) xmalloc (saved_command_line_size); - saved_command_line[0] = '\0'; + saved_command_line = (char *) xstrdup (""); instream = stdin; #ifdef __MINGW32__ diff --git a/gdb/top.c b/gdb/top.c index 558f943..1a5c3f9 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -125,11 +125,9 @@ char *current_directory; /* The directory name is actually stored here (usually). */ char gdb_dirbuf[1024]; -/* Buffer used for reading command lines, and the size - allocated for it so far. */ - +/* The last command line executed on the console. Used for command + repetitions. */ char *saved_command_line; -int saved_command_line_size = 100; /* Nonzero if the current command is modified by "server ". This affects things like recording into the command history, commands @@ -1222,13 +1220,8 @@ command_line_input (const char *prompt_arg, int repeat, char *annotation_suffix) /* Save into global buffer if appropriate. */ if (repeat) { - if (linelength > saved_command_line_size) - { - saved_command_line - = (char *) xrealloc (saved_command_line, linelength); - saved_command_line_size = linelength; - } - strcpy (saved_command_line, linebuffer); + xfree (saved_command_line); + saved_command_line = xstrdup (linebuffer); return saved_command_line; } diff --git a/gdb/top.h b/gdb/top.h index c450c6e..f3b080b 100644 --- a/gdb/top.h +++ b/gdb/top.h @@ -22,7 +22,6 @@ /* From top.c. */ extern char *saved_command_line; -extern int saved_command_line_size; extern FILE *instream; extern int in_user_command; extern int confirm; -- 2.7.4