Simplify saved_command_line handling
authorPedro Alves <palves@redhat.com>
Wed, 9 Mar 2016 18:25:00 +0000 (18:25 +0000)
committerPedro Alves <palves@redhat.com>
Wed, 9 Mar 2016 18:25:00 +0000 (18:25 +0000)
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.

gdb/ChangeLog
gdb/event-top.c
gdb/main.c
gdb/top.c
gdb/top.h

index 881d23104d462e4eac77ae6bcb69cbfe695a2a34..bc2e99efea970af4f5ba0c83cedb0a8eda1166c8 100644 (file)
@@ -1,3 +1,15 @@
+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.
index 885723594862bce99a1de29ce5b7fd3c435adf39..f112c52a89c2d704f211a631286128e456e9e051 100644 (file)
@@ -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);
index a338b9014cb34b5651c115a43dc4aaf24f9d8053..93ed98f11014b2644c09c2bb26bcb53c3c290a53 100644 (file)
@@ -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__
index 558f943d85012d857f9191e7e7cc1b36e976b379..1a5c3f9aef71b6bb919eccf0eeeed349d45dbbed 100644 (file)
--- 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;
     }
 
index c450c6e1ae8513f3b93d3e2b8204beadee890a06..f3b080bf9d1e205b37e4bcf02a78526c7ba41004 100644 (file)
--- 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;
This page took 0.051238 seconds and 4 git commands to generate.