Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 1/4] gdb/python: check for nullptr before calling evpy_add_attribute
@ 2026-09-14 19:19 Simon Marchi
  2026-09-14 19:19 ` [PATCH 2/4] gdb/python: collapse some nested ifs Simon Marchi
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Simon Marchi @ 2026-09-14 19:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Found by Claude while I was reviewing some patches: gdbpy_borrowed_ref's
constructor asserts that the object is not nullptr.  Some call sites can
in theory pass nullptr (although very unlikely, only on memory
allocation failure kind of errors), fix them.

Change-Id: I75141ce7a4d6392eaffaf3e4cfd06a6e84c1e81f
---
 gdb/python/py-connection.c | 3 ++-
 gdb/python/py-tui.c        | 3 ++-
 gdb/python/python.c        | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/gdb/python/py-connection.c b/gdb/python/py-connection.c
index d2085960be4d..e2769871d3d7 100644
--- a/gdb/python/py-connection.c
+++ b/gdb/python/py-connection.c
@@ -143,7 +143,8 @@ emit_connection_event (process_stratum_target *target,
     return -1;
 
   gdbpy_ref<> conn = target_to_connection_object (target);
-  if (evpy_add_attribute (event_obj, "connection", conn) < 0)
+  if (conn == nullptr
+      || evpy_add_attribute (event_obj, "connection", conn) < 0)
     return -1;
 
   return evpy_emit_event (event_obj, registry);
diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c
index 465fbd2fe6d1..7213158cdbe3 100644
--- a/gdb/python/py-tui.c
+++ b/gdb/python/py-tui.c
@@ -605,7 +605,8 @@ gdbpy_tui_enabled (bool state)
     }
 
   gdbpy_ref<> code (PyBool_FromLong (state));
-  if (evpy_add_attribute (event_obj, "enabled", code) < 0
+  if (code == nullptr
+      || evpy_add_attribute (event_obj, "enabled", code) < 0
       || evpy_emit_event (event_obj, gdb_py_events.tui_enabled) < 0)
     gdbpy_print_stack ();
 }
diff --git a/gdb/python/python.c b/gdb/python/python.c
index df9f7c690064..01f4aa275ef9 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -2500,7 +2500,8 @@ emit_exiting_event (int exit_code)
     return -1;
 
   gdbpy_ref<> code = gdb_py_object_from_longest (exit_code);
-  if (evpy_add_attribute (event_obj, "exit_code", code) < 0)
+  if (code == nullptr
+      || evpy_add_attribute (event_obj, "exit_code", code) < 0)
     return -1;
 
   return evpy_emit_event (event_obj, gdb_py_events.gdb_exiting);

base-commit: 45e21c702fb0c4e273398b24a26096fd43dc512d
-- 
2.55.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-09-14 19:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-14 19:19 [PATCH 1/4] gdb/python: check for nullptr before calling evpy_add_attribute Simon Marchi
2026-09-14 19:19 ` [PATCH 2/4] gdb/python: collapse some nested ifs Simon Marchi
2026-09-14 19:35   ` Tom Tromey
2026-09-14 19:46     ` Simon Marchi
2026-09-14 19:19 ` [PATCH 3/4] gdb/python: rename evregpy_no_listeners_p to evregpy_has_listeners_p Simon Marchi
2026-09-14 19:38   ` Tom Tromey
2026-09-14 19:19 ` [PATCH 4/4] gdb/python: remove more useless casts Simon Marchi
2026-09-14 19:39   ` Tom Tromey
2026-09-14 19:47     ` Simon Marchi
2026-09-14 19:24 ` [PATCH 1/4] gdb/python: check for nullptr before calling evpy_add_attribute Tom Tromey
2026-09-14 19:43   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox