Initialize variable word in complete
authorJan Vrany <jan.vrany@fit.cvut.cz>
Thu, 30 May 2019 12:04:26 +0000 (13:04 +0100)
committerJan Vrany <jan.vrany@fit.cvut.cz>
Thu, 30 May 2019 12:05:40 +0000 (13:05 +0100)
The complete function should set parameter word to the end of the
word to complete. However, completion_find_completion_word may fail,
leaving word uninitialized.

To make sure word is always set, initialize it to the completion point
which is the end of the line parameter.

gdb/Changelog

PR cli/24587
* completer.c (complete): Initialize variable word.

gdb/ChangeLog
gdb/completer.c

index 2ab3615be6e52ba83579b4383c543932bac89bab..a32c6060ef238dcd0ebb6b5c9ebff3903ba6ea3a 100644 (file)
@@ -1,3 +1,8 @@
+2019-05-30  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+       PR cli/24587
+       * completer.c (complete): Initialize variable word.
+
 2019-05-29  Sergio Durigan Junior  <sergiodj@redhat.com>
 
        Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1708192
index cc2f80bc66e0247b761c46dbe5678eb40bd1030b..24c8446630746e2cc700042986bc6d0d65daf992 100644 (file)
@@ -1622,6 +1622,13 @@ complete (const char *line, char const **word, int *quote_char)
   completion_tracker tracker_handle_completions;
   completion_tracker *tracker;
 
+  /* The WORD should be set to the end of word to complete.  We initialize
+     to the completion point which is assumed to be at the end of LINE.
+     This leaves WORD to be initialized to a sensible value in cases
+     completion_find_completion_word() fails i.e., throws an exception.
+     See bug 24587. */
+  *word = line + strlen (line);
+
   try
     {
       *word = completion_find_completion_word (tracker_handle_brkchars,