public inbox for gdb-cvs@sourceware.org help / color / mirror / Atom feed
From: Tom Tromey <tromey@sourceware.org> To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Don't allow NULL as an argument to block_global_block Date: Sun, 19 Feb 2023 23:37:24 +0000 (GMT) [thread overview] Message-ID: <20230219233724.A4A5C3858D37@sourceware.org> (raw) 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) {
reply other threads:[~2023-02-19 23:37 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230219233724.A4A5C3858D37@sourceware.org \ --to=tromey@sourceware.org \ --cc=gdb-cvs@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: linkBe 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).