hash table iterator callback functions int vs. bfd_boolean
[binutils-gdb.git] / bfd / ecofflink.c
index dde5593636acd91acc0afb0590160dd282858296..ef3bce72199764fd69ffa3c9f6b879a96d2d5b9f 100644 (file)
@@ -1,5 +1,5 @@
 /* Routines to link ECOFF debugging information.
-   Copyright (C) 1993-2020 Free Software Foundation, Inc.
+   Copyright (C) 1993-2021 Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support, <ian@cygnus.com>.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -1464,12 +1464,10 @@ ecoff_write_symhdr (bfd *abfd,
       != swap->external_hdr_size)
     goto error_return;
 
-  if (buff != NULL)
-    free (buff);
+  free (buff);
   return TRUE;
  error_return:
-  if (buff != NULL)
-    free (buff);
+  free (buff);
   return FALSE;
 }
 
@@ -1491,10 +1489,12 @@ bfd_ecoff_write_debug (bfd *abfd,
     return FALSE;
 
 #define WRITE(ptr, count, size, offset) \
-  BFD_ASSERT (symhdr->offset == 0 \
-             || (bfd_vma) bfd_tell (abfd) == symhdr->offset); \
-  if (bfd_bwrite (debug->ptr, (bfd_size_type) size * symhdr->count, abfd)\
-      != size * symhdr->count) \
+  BFD_ASSERT (symhdr->offset == 0                              \
+             || (bfd_vma) bfd_tell (abfd) == symhdr->offset);  \
+  if (symhdr->count != 0                                       \
+      && bfd_bwrite (debug->ptr,                               \
+                    (bfd_size_type) size * symhdr->count,      \
+                    abfd) != size * symhdr->count)             \
     return FALSE;
 
   WRITE (line, cbLine, sizeof (unsigned char), cbLineOffset);
@@ -1652,7 +1652,7 @@ bfd_ecoff_write_accumulated_debug (void * handle,
   /* The external strings and symbol are not converted over to using
      shuffles.  FIXME: They probably should be.  */
   amt = debug->symbolic_header.issExtMax;
-  if (bfd_bwrite (debug->ssext, amt, abfd) != amt)
+  if (amt != 0 && bfd_bwrite (debug->ssext, amt, abfd) != amt)
     goto error_return;
   if ((debug->symbolic_header.issExtMax & (swap->debug_align - 1)) != 0)
     {
@@ -1682,16 +1682,14 @@ bfd_ecoff_write_accumulated_debug (void * handle,
                  == (bfd_vma) bfd_tell (abfd)));
 
   amt = debug->symbolic_header.iextMax * swap->external_ext_size;
-  if (bfd_bwrite (debug->external_ext, amt, abfd) != amt)
+  if (amt != 0 && bfd_bwrite (debug->external_ext, amt, abfd) != amt)
     goto error_return;
 
-  if (space != NULL)
-    free (space);
+  free (space);
   return TRUE;
 
  error_return:
-  if (space != NULL)
-    free (space);
+  free (space);
   return FALSE;
 }
 \f
@@ -2320,12 +2318,11 @@ lookup_line (bfd *abfd,
 
       if (len != 0)
        {
-         if (line_info->find_buffer != NULL)
-           free (line_info->find_buffer);
+         free (line_info->find_buffer);
          buffer = (char *) bfd_malloc ((bfd_size_type) len);
+         line_info->find_buffer = buffer;
          if (buffer == NULL)
            return FALSE;
-         line_info->find_buffer = buffer;
        }
 
       if (function_name != NULL)