public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Don't allow NULL as an argument to block_global_block
@ 2023-02-19 23:37 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2023-02-19 23:37 UTC (permalink / raw)
  To: gdb-cvs

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

commit 8f14fd112036be4300c81492a4659d518d9caf24
Author: Tom Tromey <tom@tromey.com>
Date:   Thu Jan 19 17:22:04 2023 -0700

    Don't allow NULL as an argument to block_global_block
    
    block_global_block has special behavior when the block is NULL.
    Remove this and patch up the callers instead.

Diff:
---
 gdb/block.c      |  6 +-----
 gdb/cp-support.c | 15 ++++++++-------
 gdb/symtab.c     |  5 +++--
 3 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/gdb/block.c b/gdb/block.c
index d21729f069d..5751a6b6f84 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -378,15 +378,11 @@ block_static_block (const struct block *block)
   return block;
 }
 
-/* Return the static block associated to BLOCK.  Return NULL if block
-   is NULL.  */
+/* Return the static block associated to BLOCK.  */
 
 const struct block *
 block_global_block (const struct block *block)
 {
-  if (block == NULL)
-    return NULL;
-
   while (block->superblock () != NULL)
     block = block->superblock ();
 
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index f7767c980c5..fe56e610a5c 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -1309,14 +1309,15 @@ add_symbol_overload_list_namespace (const char *func_name,
   /* Look in the static block.  */
   block = get_selected_block (0);
   block = block == nullptr ? nullptr : block_static_block (block);
-  if (block)
-    add_symbol_overload_list_block (name, block, overload_list);
-
-  /* Look in the global block.  */
-  block = block_global_block (block);
-  if (block)
-    add_symbol_overload_list_block (name, block, overload_list);
+  if (block != nullptr)
+    {
+      add_symbol_overload_list_block (name, block, overload_list);
 
+      /* Look in the global block.  */
+      block = block_global_block (block);
+      if (block)
+	add_symbol_overload_list_block (name, block, overload_list);
+    }
 }
 
 /* Search the namespace of the given type and namespace of and public
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 598e243b24c..3a380f131cd 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2597,7 +2597,8 @@ lookup_global_symbol (const char *name,
   /* If a block was passed in, we want to search the corresponding
      global block first.  This yields "more expected" behavior, and is
      needed to support 'FILENAME'::VARIABLE lookups.  */
-  const struct block *global_block = block_global_block (block);
+  const struct block *global_block
+    = block == nullptr ? nullptr : block_global_block (block);
   symbol *sym = NULL;
   if (global_block != nullptr)
     {
@@ -5831,7 +5832,7 @@ default_collect_symbol_completion_matches_break_on
 
   b = get_selected_block (0);
   surrounding_static_block = b == nullptr ? nullptr : block_static_block (b);
-  surrounding_global_block = block_global_block (b);
+  surrounding_global_block = b == nullptr : nullptr : block_global_block (b);
   if (surrounding_static_block != NULL)
     while (b != surrounding_static_block)
       {

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

only message in thread, other threads:[~2023-02-19 23:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-19 23:37 [binutils-gdb] Don't allow NULL as an argument to block_global_block 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).