public inbox for binutils-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] PowerPC md_end: Don't htab_delete(NULL)
@ 2022-07-12  2:35 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2022-07-12  2:35 UTC (permalink / raw)
  To: bfd-cvs

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

commit a14413ddff3009418711b9f78a7d3dc7ac10dab0
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Jul 12 11:17:38 2022 +0930

    PowerPC md_end: Don't htab_delete(NULL)
    
    It might be possible to hit md_end before md_begin is called, don't
    segfault if so.  Also, remove a useless check.
    
            * gas/config/tc-ppc.c (insn_calloc): Remove needless overflow
            check.
            (ppc_md_end): Check ppc_hash before deleting.  Clear ppc_hash.

Diff:
---
 gas/config/tc-ppc.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
index ac61cd8f122..5015777d600 100644
--- a/gas/config/tc-ppc.c
+++ b/gas/config/tc-ppc.c
@@ -1620,14 +1620,8 @@ insn_validate (const struct powerpc_opcode *op)
 static void *
 insn_calloc (size_t n, size_t size)
 {
-  size_t amt;
-  void *ret;
-  if (gas_mul_overflow (n, size, &amt))
-    {
-      obstack_alloc_failed_handler ();
-      abort ();
-    }
-  ret = obstack_alloc (&insn_obstack, amt);
+  size_t amt = n * size;
+  void *ret = obstack_alloc (&insn_obstack, amt);
   memset (ret, 0, amt);
   return ret;
 }
@@ -1903,8 +1897,12 @@ md_begin (void)
 void
 ppc_md_end (void)
 {
-  htab_delete (ppc_hash);
-  _obstack_free (&insn_obstack, NULL);
+  if (ppc_hash)
+    {
+      htab_delete (ppc_hash);
+      _obstack_free (&insn_obstack, NULL);
+    }
+  ppc_hash = NULL;
 }
 
 void


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

only message in thread, other threads:[~2022-07-12  2:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-12  2:35 [binutils-gdb] PowerPC md_end: Don't htab_delete(NULL) Alan Modra

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