public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Use gdb::optional for sigint_ours
@ 2022-12-13 20:07 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-12-13 20:07 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d2f803afd5a3ae16933a3adb8dca9b16a01551ce

commit d2f803afd5a3ae16933a3adb8dca9b16a01551ce
Author: Tom Tromey <tromey@adacore.com>
Date:   Mon Dec 12 10:17:18 2022 -0700

    Use gdb::optional for sigint_ours
    
    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.

Diff:
---
 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<sighandler_t> sigint_ours;
 #ifdef SIGQUIT
-static sighandler_t sigquit_ours;
+static gdb::optional<sighandler_t> 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
 	}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-13 20:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-13 20:07 [binutils-gdb] Use gdb::optional for sigint_ours Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).