binutils-gdb/gdb/cli
Tom de Vries fb7806c7a4 [gdb/cli] Fix use of uninitialized variable in complete_command
When building gdb on ubuntu 16.04 with gcc 5.4.0, and running the gdb
testsuite we run into:
...
FAIL: gdb.linespec/explicit.exp: complete after -line: \
  cmd complete "b -line argument " (timeout)
...

The failure is reproducible outside the testsuite like this:
...
$ gdb -q build/gdb/testsuite/outputs/gdb.linespec/explicit/explicit \
  -ex "complete b -line argument"
Reading symbols from \
  build/gdb/testsuite/outputs/gdb.linespec/explicit/explicit...
terminate called after throwing an instance of 'std::length_error'
  what():  basic_string::_M_create
  Aborted (core dumped)
...

The problem is here in complete_command:
...
  completion_result result = complete (arg, &word, &quote_char);

  std::string arg_prefix (arg, word - arg);

  if (result.number_matches != 0)
...
The problem is that the word variable is not initialized when
result.number_matches == 0, but the variable is still used in the arg_prefix
initialization.

Fix this by guarding the arg_prefix initialization with the
'result.number_matches != 0' test.

Build and tested on x86_64-linux.

gdb/ChangeLog:

2019-05-21  Tom de Vries  <tdevries@suse.de>

	PR cli/24587
	* cli/cli-cmds.c (complete_command): Fix use of unitialized variable.
2019-05-21 16:32:41 +02:00
..
cli-cmds.c [gdb/cli] Fix use of uninitialized variable in complete_command 2019-05-21 16:32:41 +02:00
cli-cmds.h Normalize include guards in gdb 2019-02-07 03:27:23 -07:00
cli-decode.c Change valid_user_defined_cmd_name_p to return bool 2019-05-04 14:13:27 -06:00
cli-decode.h Normalize include guards in gdb 2019-02-07 03:27:23 -07:00
cli-dump.c Normalize includes to use common/ 2019-01-25 15:28:16 -07:00
cli-interp.c Add debug redirect option 2019-05-17 14:21:47 +01:00
cli-interp.h Add debug redirect option 2019-05-17 14:21:47 +01:00
cli-logging.c Add debug redirect option 2019-05-17 14:21:47 +01:00
cli-script.c Replace throw_exception with throw in some cases 2019-04-08 09:05:41 -06:00
cli-script.h Normalize include guards in gdb 2019-02-07 03:27:23 -07:00
cli-setshow.c Update copyright year range in all GDB files. 2019-01-01 10:01:51 +04:00
cli-setshow.h Normalize include guards in gdb 2019-02-07 03:27:23 -07:00
cli-style.c Add the "set style source" command 2019-03-14 05:47:11 -06:00
cli-style.h Add the "set style source" command 2019-03-14 05:47:11 -06:00
cli-utils.c Update copyright year range in all GDB files. 2019-01-01 10:01:51 +04:00
cli-utils.h Normalize include guards in gdb 2019-02-07 03:27:23 -07:00