From patchwork Tue May 21 14:36:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 32784 Received: (qmail 109385 invoked by alias); 21 May 2019 14:36:39 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 109133 invoked by uid 89); 21 May 2019 14:36:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=HTo:U*palves X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 21 May 2019 14:36:38 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 35249AE6D; Tue, 21 May 2019 14:36:36 +0000 (UTC) Date: Tue, 21 May 2019 16:36:34 +0200 From: Tom de Vries To: gdb-patches@sourceware.org, Pedro Alves , Jan Vrany Subject: [committed][gdb/cli] Fix use of uninitialized variable in complete_command Message-ID: <20190521143632.GA21040@delia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-IsSubscribed: yes Hi, 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, "e_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. Committed to trunk. Thanks, - Tom [gdb/cli] Fix use of uninitialized variable in complete_command gdb/ChangeLog: 2019-05-21 Tom de Vries PR cli/24587 * cli/cli-cmds.c (complete_command): Fix use of unitialized variable. --- gdb/cli/cli-cmds.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 332078b910..daf409a558 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, "e_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