public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 1/2] gdbsupport: allow passing nullptr to checked_static_cast
Date: Tue, 31 Jan 2023 10:57:20 -0500	[thread overview]
Message-ID: <20230131155721.21847-1-simon.marchi@efficios.com> (raw)

Both static_cast and dynamic_cast handle nullptr (they return nullptr),
so I think checked_static_cast should too.  This will allow doing a null
check after a checked_static_cast:

  cooked_index_vector *table
    = (gdb::checked_static_cast<cooked_index_vector *>
       (per_bfd->index_table.get ()));
  if (table != nullptr)
    return;

Change-Id: If5c3134e63696f8e417c87b5f3901240c9f7ea97
---
 gdbsupport/gdb-checked-static-cast.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gdbsupport/gdb-checked-static-cast.h b/gdbsupport/gdb-checked-static-cast.h
index cc298733fadb..bc75244bddd0 100644
--- a/gdbsupport/gdb-checked-static-cast.h
+++ b/gdbsupport/gdb-checked-static-cast.h
@@ -54,6 +54,9 @@ checked_static_cast (V *v)
 		 "types must be related");
 
 #ifdef DEVELOPMENT
+  if (v == nullptr)
+    return nullptr;
+
   T result = dynamic_cast<T> (v);
   gdb_assert (result != nullptr);
 #else
-- 
2.39.1


             reply	other threads:[~2023-01-31 15:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-31 15:57 Simon Marchi [this message]
2023-01-31 15:57 ` [PATCH 2/2] gdb: add nullptr check to cooked_index_functions::dump Simon Marchi
2023-01-31 17:35   ` Tom Tromey
2023-01-31 18:22     ` Simon Marchi
2023-01-31 17:35 ` [PATCH 1/2] gdbsupport: allow passing nullptr to checked_static_cast Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230131155721.21847-1-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).