diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 51e946f7020..86f522d42e0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+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-18  Andrew Burgess  <andrew.burgess@embecosm.com>
 
 	PR gdb/18644:
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 332078b910f..daf409a5580 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -248,10 +248,10 @@ complete_command (const char *arg, int from_tty)
 
   completion_result result = complete (arg, &word, &quote_char);
 
-  std::string arg_prefix (arg, word - arg);
-
   if (result.number_matches != 0)
     {
+      std::string arg_prefix (arg, word - arg);
+
       if (result.number_matches == 1)
 	printf_unfiltered ("%s%s\n", arg_prefix.c_str (), result.match_list[0]);
       else