From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 59085 invoked by alias); 6 Oct 2018 19:32:16 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 59064 invoked by uid 89); 6 Oct 2018 19:32:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=237A, 7628, 31f4, D0EB X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 06 Oct 2018 19:32:14 +0000 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4EDE45F72B; Sat, 6 Oct 2018 19:32:13 +0000 (UTC) Received: from localhost (unused-10-15-17-196.yyz.redhat.com [10.15.17.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21EE32010D67; Sat, 6 Oct 2018 19:32:13 +0000 (UTC) From: Sergio Durigan Junior To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFC] Avoid crash when calling warning too early References: <20181006192007.1945-1-tom@tromey.com> Date: Sat, 06 Oct 2018 19:32:00 -0000 In-Reply-To: <20181006192007.1945-1-tom@tromey.com> (Tom Tromey's message of "Sat, 6 Oct 2018 13:20:07 -0600") Message-ID: <87woquq3b7.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2018-10/txt/msg00151.txt.bz2 On Saturday, October 06 2018, Tom Tromey wrote: > I happened to notice that if you pass the name of an existing file > (not a directory) as the argument to --data-directory, gdb will crash: > > $ ./gdb -nx --data-directory ./gdb > ../../binutils-gdb/gdb/target.c:590:56: runtime error: member call on null pointer of type 'struct target_ops' > > This happens because warning ends up calling > target_supports_terminal_ours, which calls current_top_target, which > returns nullptr this early. > > This fixes the problem by handling this case specially in > target_supports_terminal_ours. > > I wasn't sure whether this warranted a test case, hence the RFC. Thanks for the patch. I remember stumbling upon this issue a while ago, and had a similar patch to fix it, but I think I forgot to submit it. > gdb/ChangeLog > 2018-10-06 Tom Tromey > > * target.c (target_supports_terminal_ours): Handle case where > current_top_target returns nullptr. > --- > gdb/ChangeLog | 5 +++++ > gdb/target.c | 5 +++++ > 2 files changed, 10 insertions(+) > > diff --git a/gdb/target.c b/gdb/target.c > index 2d98954b54..a261155f29 100644 > --- a/gdb/target.c > +++ b/gdb/target.c > @@ -587,6 +587,11 @@ target_terminal::info (const char *arg, int from_tty) > int > target_supports_terminal_ours (void) > { > + /* This can be called before there is any target, so we must check > + for nullptr here. */ > + target_ops *top = current_top_target (); > + if (top == nullptr) > + return false; > return current_top_target ()->supports_terminal_ours (); > } The patch looks good to me. My only question is about whether we still require a newline between variable declarations and the rest of the code. I still follow this rule (because I think it improves code readability), but now with C++11 I'm not sure if it's still being enforced. Thanks, -- Sergio GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36 Please send encrypted e-mail if possible http://sergiodj.net/