public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdbsupport: allow passing nullptr to checked_static_cast
@ 2023-01-31 18:22 Simon Marchi
  0 siblings, 0 replies; only message in thread
From: Simon Marchi @ 2023-01-31 18:22 UTC (permalink / raw)
  To: gdb-cvs

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

commit d7789889b1839c3c0f64c6738b0d8517ccead049
Author: Simon Marchi <simon.marchi@efficios.com>
Date:   Tue Jan 31 10:57:20 2023 -0500

    gdbsupport: allow passing nullptr to checked_static_cast
    
    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

Diff:
---
 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 cc298733fad..bc75244bddd 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

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

only message in thread, other threads:[~2023-01-31 18:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-31 18:22 [binutils-gdb] gdbsupport: allow passing nullptr to checked_static_cast Simon Marchi

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).