Initialize variable word in complete

Message ID 20190522111453.12958-1-jan.vrany@fit.cvut.cz
State New
Headers show
Series
  • Initialize variable word in complete
Related show

Commit Message

Jan Vrany May 22, 2019, 11:14 a.m.
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   | 5 +++++
 gdb/completer.c | 7 +++++++
 2 files changed, 12 insertions(+)

-- 
2.20.1

Comments

Tom Tromey May 29, 2019, 6:37 p.m. | #1
>>>>> "Jan" == Jan Vrany <jan.vrany@fit.cvut.cz> writes:


Jan> gdb/Changelog

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

Thank you.  This is ok.

Tom
Jan Vrany May 30, 2019, 12:21 p.m. | #2
Hi,

fixed and pushed, thanks! 

Jan

On Wed, 2019-05-29 at 11:40 -0700, Keith Seitz wrote:
> Hi,

> 

> Tom already approved this, but I just noticed a little / obvious typo. If

> you catch this before pushing, please change. Otherwise, don't worry about it.

> 

> On 5/22/19 4:14 AM, Jan Vrany wrote:

> > diff --git a/gdb/completer.c b/gdb/completer.c

> > index cc2f80bc66..954f435259 100644

> > --- a/gdb/completer.c

> > +++ b/gdb/completer.c

> > @@ -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);

>                     ^^^^^^^^^^^^

> 

> That should read "strlen (line);".

> 

> Keith

> 

> > +

> >    try

> >      {

> >        *word = completion_find_completion_word (tracker_handle_brkchars,

>

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index b0b7503b28..ff58d8079f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@ 
+2019-05-22  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	PR cli/24587
+	* completer.c (complete): Initialize variable word.
+
 2019-05-21  Andrew Burgess  <andrew.burgess@embecosm.com>
 
 	PR gdb/18644:
diff --git a/gdb/completer.c b/gdb/completer.c
index cc2f80bc66..954f435259 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -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,