diff options
author | Pedro Alves <palves@redhat.com> | 2016-03-09 18:25:00 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2016-03-09 18:25:00 +0000 |
commit | 2669cade3dcebf5d572bcd535cf21934cbc1633c (patch) | |
tree | 4b4de5e2d89d3cf97ca0da1a53d4154ce9d7fa7b /gdb/top.c | |
parent | 187212b3c1aa55d9a5b544a6af3af0b5ce457403 (diff) | |
download | gdb-2669cade3dcebf5d572bcd535cf21934cbc1633c.zip gdb-2669cade3dcebf5d572bcd535cf21934cbc1633c.tar.gz gdb-2669cade3dcebf5d572bcd535cf21934cbc1633c.tar.bz2 |
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 <palves@redhat.com>
* 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.
Diffstat (limited to 'gdb/top.c')
-rw-r--r-- | gdb/top.c | 15 |
1 files changed, 4 insertions, 11 deletions
@@ -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; } |