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.
+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.
+
2016-03-09 Pedro Alves <palves@redhat.com>
* event-top.c: Include buffer.h.
/* 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);
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__
/* 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
/* 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;
}
/* 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;