From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by sourceware.org (Postfix) with ESMTPS id C941B385F3C5 for ; Mon, 12 Dec 2022 18:11:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C941B385F3C5 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-io1-xd2a.google.com with SMTP id r72so382323iod.5 for ; Mon, 12 Dec 2022 10:11:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q9KtA8XQNRZ3+y0W843eqDiN9yO/MaU+xqYqfCGxLYs=; b=ZKnTIzTrUCVYOS55ANTk0pMewLJMeWEzbK251Sl9zN3kSeL2rg8lkxEuLJ8JenH/lB ejcjioOGCG0JECb34Voq00lhowkv6dVLMQwBmIyot8jSVnR3OfuLfSAiD/ATuvq7WwMo CUMS+P2KRuS7Xe5pC4TcAci4vO6ms9L01jw3sAs8FT6iqxtuNwMGimjzPJFCar1aDoJr QCd61bL65TyBsvOlX3rgTejqF55YA0PEwZgLcG2+mecq9lJanbecqSlkR3ZWrlAjaUt7 Ir+6FsRbyD5XXAUga2Ydrh71/z2V9yWdyfb5jwpOgyzedXgmWeMLyBYBL5Uc4lV2lPkM 3Vtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q9KtA8XQNRZ3+y0W843eqDiN9yO/MaU+xqYqfCGxLYs=; b=iIz1EG6jU035ldb1LkUKQbW81VY1sHa+yEKjZl9dQHmecmeeCgeG0W81n9FPzb7tLR V0qT4nJ2JtYOpptccwkQ//MYxgbohp9MIOy29vsQQHF3a/Ybb+RfOdTczOzMYO0NchHx HKk2PUNTBEPwLfJSe9l+9VjKKEOsWUEbvTVP90wvXIla9pjYGHUrTJBZrM+DACKsY3Qs mSKP08k3J5Ud1LQEgy95dIYbtOkQDI3MWFPawxUIXT4xNo2Vzq0fXm8Y1M7Fedn/HxoO 3+Ryzrledj38U4jjuO41DLEQY9eDLUieRiD5kD20Lp5lT2eQBS+dgTWPTIho/Mi+8yoT mXbw== X-Gm-Message-State: ANoB5plUX+6I9H2MSdGwTYR7z9MjkDb4gfIghyJ1e7fg4MHFEpOVcLap vYmhC5mES9yRe8eQyY4d/JoLZBoxUcWBtd36 X-Google-Smtp-Source: AA0mqf44v3+CGqOpS8kzBxQKMV3SRpliylAWNphAVc78D5mLTHc0k/8WAaVwTOKGEQyFeGRDCl6KDA== X-Received: by 2002:a5d:9cd1:0:b0:6e2:d84f:8905 with SMTP id w17-20020a5d9cd1000000b006e2d84f8905mr11750142iow.7.1670868685139; Mon, 12 Dec 2022 10:11:25 -0800 (PST) Received: from localhost.localdomain (97-122-76-186.hlrn.qwest.net. [97.122.76.186]) by smtp.gmail.com with ESMTPSA id y24-20020a056638229800b00389e9e6112csm131335jas.70.2022.12.12.10.11.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 10:11:24 -0800 (PST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 2/4] Use gdb::optional for sigint_ours Date: Mon, 12 Dec 2022 11:11:11 -0700 Message-Id: <20221212181113.1501286-3-tromey@adacore.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20221212181113.1501286-1-tromey@adacore.com> References: <20221212181113.1501286-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: sigint_ours (and sigquit_ours) can be used without being set. Avoid this problem by changing them to gdb::optional and checking that they are in fact set before using the value. --- gdb/inflow.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gdb/inflow.c b/gdb/inflow.c index 5477624bcd5..da2005a9318 100644 --- a/gdb/inflow.c +++ b/gdb/inflow.c @@ -113,9 +113,9 @@ static struct terminal_info *get_inflow_inferior_data (struct inferior *); we save our handlers in these two variables and set SIGINT and SIGQUIT to SIG_IGN. */ -static sighandler_t sigint_ours; +static gdb::optional sigint_ours; #ifdef SIGQUIT -static sighandler_t sigquit_ours; +static gdb::optional sigquit_ours; #endif /* The name of the tty (from the `tty' command) that we're giving to @@ -501,9 +501,13 @@ child_terminal_ours_1 (target_terminal_state desired_state) if (!job_control && desired_state == target_terminal_state::is_ours) { - signal (SIGINT, sigint_ours); + if (sigint_ours.has_value ()) + signal (SIGINT, *sigint_ours); + sigint_ours.reset (); #ifdef SIGQUIT - signal (SIGQUIT, sigquit_ours); + if (sigquit_ours.has_value ()) + signal (SIGQUIT, *sigquit_ours); + sigquit_ours.reset (); #endif } -- 2.34.3