* aoutx.h, elfcode.h, coff-alpha.c, bout.c, ecoff.c, ecofflink.c,

elf32-hppa.c, elf32-mips.c, linker.c, som.c, sunos.c: If malloc(0)
	returns NULL, it is not an error.  It's possible that some of
	these checks are not necessary (because the size can never be
	zero), but putting in the checks is the conservative thing to do
	in light of the fact that some of these malloc calls replaced
	unchecked alloca calls, in which a zero argument would work fine.
This commit is contained in:
Jim Kingdon
1994-03-17 18:54:48 +00:00
parent f09d749f4c
commit 8eb5d4be69
3 changed files with 159 additions and 143 deletions

View File

@ -1,3 +1,13 @@
Thu Mar 17 10:37:07 1994 Jim Kingdon (kingdon@lioth.cygnus.com)
* aoutx.h, elfcode.h, coff-alpha.c, bout.c, ecoff.c, ecofflink.c,
elf32-hppa.c, elf32-mips.c, linker.c, som.c, sunos.c: If malloc(0)
returns NULL, it is not an error. It's possible that some of
these checks are not necessary (because the size can never be
zero), but putting in the checks is the conservative thing to do
in light of the fact that some of these malloc calls replaced
unchecked alloca calls, in which a zero argument would work fine.
Thu Mar 17 11:44:45 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com) Thu Mar 17 11:44:45 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com)
* reloc.c (bfd_generic_get_relocated_section_contents): Don't fail * reloc.c (bfd_generic_get_relocated_section_contents): Don't fail

View File

@ -125,7 +125,6 @@ DESCRIPTION
#include <string.h> /* For strchr and friends */ #include <string.h> /* For strchr and friends */
#include "bfd.h" #include "bfd.h"
#include <sysdep.h> #include <sysdep.h>
#include <ansidecl.h>
#include "bfdlink.h" #include "bfdlink.h"
#include "libaout.h" #include "libaout.h"
@ -208,9 +207,9 @@ HOWTO(10, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"BASE32", f
#define TABLE_SIZE(TABLE) (sizeof(TABLE)/sizeof(TABLE[0])) #define TABLE_SIZE(TABLE) (sizeof(TABLE)/sizeof(TABLE[0]))
CONST struct reloc_howto_struct * CONST struct reloc_howto_struct *
DEFUN(NAME(aout,reloc_type_lookup),(abfd,code), NAME(aout,reloc_type_lookup) (abfd,code)
bfd *abfd AND bfd *abfd;
bfd_reloc_code_real_type code) bfd_reloc_code_real_type code;
{ {
#define EXT(i,j) case i: return &howto_table_ext[j] #define EXT(i,j) case i: return &howto_table_ext[j]
#define STD(i,j) case i: return &howto_table_std[j] #define STD(i,j) case i: return &howto_table_std[j]
@ -276,10 +275,10 @@ DESCRIPTION
#ifndef NAME_swap_exec_header_in #ifndef NAME_swap_exec_header_in
void void
DEFUN(NAME(aout,swap_exec_header_in),(abfd, raw_bytes, execp), NAME(aout,swap_exec_header_in) (abfd, raw_bytes, execp)
bfd *abfd AND bfd *abfd;
struct external_exec *raw_bytes AND struct external_exec *raw_bytes;
struct internal_exec *execp) struct internal_exec *execp;
{ {
struct external_exec *bytes = (struct external_exec *)raw_bytes; struct external_exec *bytes = (struct external_exec *)raw_bytes;
@ -316,10 +315,10 @@ DESCRIPTION
@var{execp} into the buffer @var{raw_bytes} ready for writing to disk. @var{execp} into the buffer @var{raw_bytes} ready for writing to disk.
*/ */
void void
DEFUN(NAME(aout,swap_exec_header_out),(abfd, execp, raw_bytes), NAME(aout,swap_exec_header_out) (abfd, execp, raw_bytes)
bfd *abfd AND bfd *abfd;
struct internal_exec *execp AND struct internal_exec *execp;
struct external_exec *raw_bytes) struct external_exec *raw_bytes;
{ {
struct external_exec *bytes = (struct external_exec *)raw_bytes; struct external_exec *bytes = (struct external_exec *)raw_bytes;
@ -354,10 +353,10 @@ DESCRIPTION
*/ */
bfd_target * bfd_target *
DEFUN(NAME(aout,some_aout_object_p),(abfd, execp, callback_to_real_object_p), NAME(aout,some_aout_object_p) (abfd, execp, callback_to_real_object_p)
bfd *abfd AND bfd *abfd;
struct internal_exec *execp AND struct internal_exec *execp;
bfd_target *(*callback_to_real_object_p) PARAMS ((bfd *))) bfd_target *(*callback_to_real_object_p) PARAMS ((bfd *));
{ {
struct aout_data_struct *rawptr, *oldrawptr; struct aout_data_struct *rawptr, *oldrawptr;
bfd_target *result; bfd_target *result;
@ -547,8 +546,8 @@ DESCRIPTION
*/ */
boolean boolean
DEFUN(NAME(aout,mkobject),(abfd), NAME(aout,mkobject) (abfd)
bfd *abfd) bfd *abfd;
{ {
struct aout_data_struct *rawptr; struct aout_data_struct *rawptr;
@ -601,9 +600,9 @@ DESCRIPTION
*/ */
enum machine_type enum machine_type
DEFUN(NAME(aout,machine_type),(arch, machine), NAME(aout,machine_type) (arch, machine)
enum bfd_architecture arch AND enum bfd_architecture arch;
unsigned long machine) unsigned long machine;
{ {
enum machine_type arch_flags; enum machine_type arch_flags;
@ -668,10 +667,10 @@ DESCRIPTION
*/ */
boolean boolean
DEFUN(NAME(aout,set_arch_mach),(abfd, arch, machine), NAME(aout,set_arch_mach) (abfd, arch, machine)
bfd *abfd AND bfd *abfd;
enum bfd_architecture arch AND enum bfd_architecture arch;
unsigned long machine) unsigned long machine;
{ {
if (! bfd_default_set_arch_mach (abfd, arch, machine)) if (! bfd_default_set_arch_mach (abfd, arch, machine))
return false; return false;
@ -871,8 +870,10 @@ adjust_n_magic (abfd, execp)
} }
boolean boolean
DEFUN (NAME(aout,adjust_sizes_and_vmas), (abfd, text_size, text_end), NAME(aout,adjust_sizes_and_vmas) (abfd, text_size, text_end)
bfd *abfd AND bfd_size_type *text_size AND file_ptr *text_end) bfd *abfd;
bfd_size_type *text_size;
file_ptr *text_end;
{ {
struct internal_exec *execp = exec_hdr (abfd); struct internal_exec *execp = exec_hdr (abfd);
@ -975,9 +976,9 @@ DESCRIPTION
request. request.
*/ */
boolean boolean
DEFUN(NAME(aout,new_section_hook),(abfd, newsect), NAME(aout,new_section_hook) (abfd, newsect)
bfd *abfd AND bfd *abfd;
asection *newsect) asection *newsect;
{ {
/* align to double at least */ /* align to double at least */
newsect->alignment_power = bfd_get_arch_info(abfd)->section_align_power; newsect->alignment_power = bfd_get_arch_info(abfd)->section_align_power;
@ -1010,12 +1011,12 @@ DEFUN(NAME(aout,new_section_hook),(abfd, newsect),
} }
boolean boolean
DEFUN(NAME(aout,set_section_contents),(abfd, section, location, offset, count), NAME(aout,set_section_contents) (abfd, section, location, offset, count)
bfd *abfd AND bfd *abfd;
sec_ptr section AND sec_ptr section;
PTR location AND PTR location;
file_ptr offset AND file_ptr offset;
bfd_size_type count) bfd_size_type count;
{ {
file_ptr text_end; file_ptr text_end;
bfd_size_type text_size; bfd_size_type text_size;
@ -1084,10 +1085,10 @@ DEFUN(NAME(aout,set_section_contents),(abfd, section, location, offset, count),
stabilised these should be inlined into their (single) caller */ stabilised these should be inlined into their (single) caller */
static boolean static boolean
DEFUN (translate_from_native_sym_flags, (sym_pointer, cache_ptr, abfd), translate_from_native_sym_flags (sym_pointer, cache_ptr, abfd)
struct external_nlist *sym_pointer AND struct external_nlist *sym_pointer;
aout_symbol_type * cache_ptr AND aout_symbol_type * cache_ptr;
bfd * abfd) bfd * abfd;
{ {
cache_ptr->symbol.section = 0; cache_ptr->symbol.section = 0;
switch (cache_ptr->type & N_TYPE) switch (cache_ptr->type & N_TYPE)
@ -1304,10 +1305,10 @@ DEFUN (translate_from_native_sym_flags, (sym_pointer, cache_ptr, abfd),
static boolean static boolean
DEFUN(translate_to_native_sym_flags,(sym_pointer, cache_ptr, abfd), translate_to_native_sym_flags (sym_pointer, cache_ptr, abfd)
struct external_nlist *sym_pointer AND struct external_nlist *sym_pointer;
asymbol *cache_ptr AND asymbol *cache_ptr;
bfd *abfd) bfd *abfd;
{ {
bfd_vma value = cache_ptr->value; bfd_vma value = cache_ptr->value;
@ -1386,8 +1387,8 @@ DEFUN(translate_to_native_sym_flags,(sym_pointer, cache_ptr, abfd),
asymbol * asymbol *
DEFUN(NAME(aout,make_empty_symbol),(abfd), NAME(aout,make_empty_symbol) (abfd)
bfd *abfd) bfd *abfd;
{ {
aout_symbol_type *new = aout_symbol_type *new =
(aout_symbol_type *)bfd_zalloc (abfd, sizeof (aout_symbol_type)); (aout_symbol_type *)bfd_zalloc (abfd, sizeof (aout_symbol_type));
@ -1456,8 +1457,8 @@ translate_symbol_table (abfd, in, ext, count, str, strsize, dynamic)
hold them all plus all the cached symbol entries. */ hold them all plus all the cached symbol entries. */
boolean boolean
DEFUN(NAME(aout,slurp_symbol_table),(abfd), NAME(aout,slurp_symbol_table) (abfd)
bfd *abfd) bfd *abfd;
{ {
bfd_size_type symbol_size; bfd_size_type symbol_size;
bfd_size_type string_size; bfd_size_type string_size;
@ -1941,8 +1942,8 @@ emit_strtab (abfd, tab)
} }
boolean boolean
DEFUN(NAME(aout,write_syms),(abfd), NAME(aout,write_syms) (abfd)
bfd *abfd) bfd *abfd;
{ {
unsigned int count ; unsigned int count ;
asymbol **generic = bfd_get_outsymbols (abfd); asymbol **generic = bfd_get_outsymbols (abfd);
@ -1993,9 +1994,9 @@ DEFUN(NAME(aout,write_syms),(abfd),
unsigned int unsigned int
DEFUN(NAME(aout,get_symtab),(abfd, location), NAME(aout,get_symtab) (abfd, location)
bfd *abfd AND bfd *abfd;
asymbol **location) asymbol **location;
{ {
unsigned int counter = 0; unsigned int counter = 0;
aout_symbol_type *symbase; aout_symbol_type *symbase;
@ -2013,10 +2014,10 @@ DEFUN(NAME(aout,get_symtab),(abfd, location),
/* Output standard relocation information to a file in target byte order. */ /* Output standard relocation information to a file in target byte order. */
void void
DEFUN(NAME(aout,swap_std_reloc_out),(abfd, g, natptr), NAME(aout,swap_std_reloc_out) (abfd, g, natptr)
bfd *abfd AND bfd *abfd;
arelent *g AND arelent *g;
struct reloc_std_external *natptr) struct reloc_std_external *natptr;
{ {
int r_index; int r_index;
asymbol *sym = *(g->sym_ptr_ptr); asymbol *sym = *(g->sym_ptr_ptr);
@ -2109,10 +2110,10 @@ DEFUN(NAME(aout,swap_std_reloc_out),(abfd, g, natptr),
/* Output extended relocation information to a file in target byte order. */ /* Output extended relocation information to a file in target byte order. */
void void
DEFUN(NAME(aout,swap_ext_reloc_out),(abfd, g, natptr), NAME(aout,swap_ext_reloc_out) (abfd, g, natptr)
bfd *abfd AND bfd *abfd;
arelent *g AND arelent *g;
register struct reloc_ext_external *natptr) register struct reloc_ext_external *natptr;
{ {
int r_index; int r_index;
int r_extern; int r_extern;
@ -2221,11 +2222,11 @@ DEFUN(NAME(aout,swap_ext_reloc_out),(abfd, g, natptr),
} \ } \
void void
DEFUN(NAME(aout,swap_ext_reloc_in), (abfd, bytes, cache_ptr, symbols), NAME(aout,swap_ext_reloc_in) (abfd, bytes, cache_ptr, symbols)
bfd *abfd AND bfd *abfd;
struct reloc_ext_external *bytes AND struct reloc_ext_external *bytes;
arelent *cache_ptr AND arelent *cache_ptr;
asymbol **symbols) asymbol **symbols;
{ {
int r_index; int r_index;
int r_extern; int r_extern;
@ -2256,11 +2257,11 @@ DEFUN(NAME(aout,swap_ext_reloc_in), (abfd, bytes, cache_ptr, symbols),
} }
void void
DEFUN(NAME(aout,swap_std_reloc_in), (abfd, bytes, cache_ptr, symbols), NAME(aout,swap_std_reloc_in) (abfd, bytes, cache_ptr, symbols)
bfd *abfd AND bfd *abfd;
struct reloc_std_external *bytes AND struct reloc_std_external *bytes;
arelent *cache_ptr AND arelent *cache_ptr;
asymbol **symbols) asymbol **symbols;
{ {
int r_index; int r_index;
int r_extern; int r_extern;
@ -2311,10 +2312,10 @@ DEFUN(NAME(aout,swap_std_reloc_in), (abfd, bytes, cache_ptr, symbols),
/* Reloc hackery */ /* Reloc hackery */
boolean boolean
DEFUN(NAME(aout,slurp_reloc_table),(abfd, asect, symbols), NAME(aout,slurp_reloc_table) (abfd, asect, symbols)
bfd *abfd AND bfd *abfd;
sec_ptr asect AND sec_ptr asect;
asymbol **symbols) asymbol **symbols;
{ {
unsigned int count; unsigned int count;
bfd_size_type reloc_size; bfd_size_type reloc_size;
@ -2450,9 +2451,9 @@ DEFUN(NAME(aout,slurp_reloc_table),(abfd, asect, symbols),
/* Write out a relocation section into an object file. */ /* Write out a relocation section into an object file. */
boolean boolean
DEFUN(NAME(aout,squirt_out_relocs),(abfd, section), NAME(aout,squirt_out_relocs) (abfd, section)
bfd *abfd AND bfd *abfd;
asection *section) asection *section;
{ {
arelent **generic; arelent **generic;
unsigned char *native, *natptr; unsigned char *native, *natptr;
@ -2499,11 +2500,11 @@ DEFUN(NAME(aout,squirt_out_relocs),(abfd, section),
/* This is stupid. This function should be a boolean predicate */ /* This is stupid. This function should be a boolean predicate */
unsigned int unsigned int
DEFUN(NAME(aout,canonicalize_reloc),(abfd, section, relptr, symbols), NAME(aout,canonicalize_reloc) (abfd, section, relptr, symbols)
bfd *abfd AND bfd *abfd;
sec_ptr section AND sec_ptr section;
arelent **relptr AND arelent **relptr;
asymbol **symbols) asymbol **symbols;
{ {
arelent *tblptr = section->relocation; arelent *tblptr = section->relocation;
unsigned int count; unsigned int count;
@ -2533,9 +2534,9 @@ DEFUN(NAME(aout,canonicalize_reloc),(abfd, section, relptr, symbols),
} }
unsigned int unsigned int
DEFUN(NAME(aout,get_reloc_upper_bound),(abfd, asect), NAME(aout,get_reloc_upper_bound) (abfd, asect)
bfd *abfd AND bfd *abfd;
sec_ptr asect) sec_ptr asect;
{ {
bfd_size_type dynrel_count = 0; bfd_size_type dynrel_count = 0;
@ -2573,9 +2574,9 @@ DEFUN(NAME(aout,get_reloc_upper_bound),(abfd, asect),
} }
unsigned int unsigned int
DEFUN(NAME(aout,get_symtab_upper_bound),(abfd), NAME(aout,get_symtab_upper_bound) (abfd)
bfd *abfd) bfd *abfd;
{ {
if (!NAME(aout,slurp_symbol_table)(abfd)) return 0; if (!NAME(aout,slurp_symbol_table)(abfd)) return 0;
@ -2584,19 +2585,19 @@ DEFUN(NAME(aout,get_symtab_upper_bound),(abfd),
/*ARGSUSED*/ /*ARGSUSED*/
alent * alent *
DEFUN(NAME(aout,get_lineno),(ignore_abfd, ignore_symbol), NAME(aout,get_lineno) (ignore_abfd, ignore_symbol)
bfd *ignore_abfd AND bfd *ignore_abfd;
asymbol *ignore_symbol) asymbol *ignore_symbol;
{ {
return (alent *)NULL; return (alent *)NULL;
} }
/*ARGSUSED*/ /*ARGSUSED*/
void void
DEFUN(NAME(aout,get_symbol_info),(ignore_abfd, symbol, ret), NAME(aout,get_symbol_info) (ignore_abfd, symbol, ret)
bfd *ignore_abfd AND bfd *ignore_abfd;
asymbol *symbol AND asymbol *symbol;
symbol_info *ret) symbol_info *ret;
{ {
bfd_symbol_info (symbol, ret); bfd_symbol_info (symbol, ret);
@ -2620,11 +2621,11 @@ DEFUN(NAME(aout,get_symbol_info),(ignore_abfd, symbol, ret),
/*ARGSUSED*/ /*ARGSUSED*/
void void
DEFUN(NAME(aout,print_symbol),(ignore_abfd, afile, symbol, how), NAME(aout,print_symbol) (ignore_abfd, afile, symbol, how)
bfd *ignore_abfd AND bfd *ignore_abfd;
PTR afile AND PTR afile;
asymbol *symbol AND asymbol *symbol;
bfd_print_symbol_type how) bfd_print_symbol_type how;
{ {
FILE *file = (FILE *)afile; FILE *file = (FILE *)afile;
@ -2664,20 +2665,15 @@ DEFUN(NAME(aout,print_symbol),(ignore_abfd, afile, symbol, how),
*/ */
boolean boolean
DEFUN(NAME(aout,find_nearest_line),(abfd, NAME(aout,find_nearest_line)
section, (abfd, section, symbols, offset, filename_ptr, functionname_ptr, line_ptr)
symbols, bfd *abfd;
offset, asection *section;
filename_ptr, asymbol **symbols;
functionname_ptr, bfd_vma offset;
line_ptr), CONST char **filename_ptr;
bfd *abfd AND CONST char **functionname_ptr;
asection *section AND unsigned int *line_ptr;
asymbol **symbols AND
bfd_vma offset AND
CONST char **filename_ptr AND
CONST char **functionname_ptr AND
unsigned int *line_ptr)
{ {
/* Run down the file looking for the filename, function and linenumber */ /* Run down the file looking for the filename, function and linenumber */
asymbol **p; asymbol **p;
@ -2774,9 +2770,9 @@ DEFUN(NAME(aout,find_nearest_line),(abfd,
/*ARGSUSED*/ /*ARGSUSED*/
int int
DEFUN(NAME(aout,sizeof_headers),(abfd, execable), NAME(aout,sizeof_headers) (abfd, execable)
bfd *abfd AND bfd *abfd;
boolean execable) boolean execable;
{ {
return adata(abfd).exec_bytes_size; return adata(abfd).exec_bytes_size;
} }
@ -2990,7 +2986,7 @@ aout_link_get_symbols (abfd)
to free them. */ to free them. */
syms = ((struct external_nlist *) syms = ((struct external_nlist *)
malloc ((size_t) count * EXTERNAL_NLIST_SIZE)); malloc ((size_t) count * EXTERNAL_NLIST_SIZE));
if (syms == (struct external_nlist *) NULL) if (syms == (struct external_nlist *) NULL && count != 0)
{ {
bfd_set_error (bfd_error_no_memory); bfd_set_error (bfd_error_no_memory);
return false; return false;
@ -3008,7 +3004,7 @@ aout_link_get_symbols (abfd)
return false; return false;
stringsize = GET_WORD (abfd, string_chars); stringsize = GET_WORD (abfd, string_chars);
strings = (char *) malloc ((size_t) stringsize); strings = (char *) malloc ((size_t) stringsize);
if (strings == NULL) if (strings == NULL && stringsize != 0)
{ {
bfd_set_error (bfd_error_no_memory); bfd_set_error (bfd_error_no_memory);
return false; return false;
@ -3545,7 +3541,7 @@ aout_link_input_bfd (finfo, input_bfd)
sym_count = obj_aout_external_sym_count (input_bfd); sym_count = obj_aout_external_sym_count (input_bfd);
symbol_map = (int *) malloc ((size_t) sym_count * sizeof (int)); symbol_map = (int *) malloc ((size_t) sym_count * sizeof (int));
if (symbol_map == NULL) if (symbol_map == NULL && sym_count != 0)
{ {
bfd_set_error (bfd_error_no_memory); bfd_set_error (bfd_error_no_memory);
return false; return false;
@ -4014,7 +4010,7 @@ aout_link_input_section (finfo, input_bfd, input_section, reloff_ptr,
/* Get the section contents. */ /* Get the section contents. */
input_size = bfd_section_size (input_bfd, input_section); input_size = bfd_section_size (input_bfd, input_section);
contents = (bfd_byte *) malloc (input_size); contents = (bfd_byte *) malloc (input_size);
if (contents == NULL) if (contents == NULL && input_size != 0)
{ {
bfd_set_error (bfd_error_no_memory); bfd_set_error (bfd_error_no_memory);
goto error_return; goto error_return;
@ -4025,7 +4021,7 @@ aout_link_input_section (finfo, input_bfd, input_section, reloff_ptr,
/* Read in the relocs. */ /* Read in the relocs. */
relocs = (PTR) malloc (rel_size); relocs = (PTR) malloc (rel_size);
if (relocs == NULL) if (relocs == NULL && rel_size != 0)
{ {
bfd_set_error (bfd_error_no_memory); bfd_set_error (bfd_error_no_memory);
goto error_return; goto error_return;

View File

@ -1609,7 +1609,7 @@ setup_sections (abfd, file_hdr)
/* First, read in space names */ /* First, read in space names */
space_strings = malloc (file_hdr->space_strings_size); space_strings = malloc (file_hdr->space_strings_size);
if (!space_strings) if (!space_strings && file_hdr->space_strings_size != 0)
{ {
bfd_set_error (bfd_error_no_memory); bfd_set_error (bfd_error_no_memory);
goto error_return; goto error_return;
@ -2098,15 +2098,11 @@ som_prep_for_fixups (abfd, syms, num_syms)
{ {
/* Handle a section symbol; these have no pointers back to the /* Handle a section symbol; these have no pointers back to the
SOM symbol info. So we just use the pointer field (udata) SOM symbol info. So we just use the pointer field (udata)
to hold the relocation count. to hold the relocation count. */
if (som_symbol_data (syms[i]) == NULL
FIXME. While we're here set the name of any section symbol || syms[i]->flags & BSF_SECTION_SYM)
to something which will not screw GDB. How do other formats
deal with this?!? */
if (som_symbol_data (syms[i]) == NULL)
{ {
syms[i]->flags |= BSF_SECTION_SYM; syms[i]->flags |= BSF_SECTION_SYM;
syms[i]->name = "L$0\002";
syms[i]->udata = (PTR) 0; syms[i]->udata = (PTR) 0;
} }
else else
@ -2677,6 +2673,14 @@ som_begin_writing (abfd)
we support only the copyright and version headers. */ we support only the copyright and version headers. */
obj_som_file_hdr (abfd)->aux_header_location = current_offset; obj_som_file_hdr (abfd)->aux_header_location = current_offset;
obj_som_file_hdr (abfd)->aux_header_size = 0; obj_som_file_hdr (abfd)->aux_header_size = 0;
if (abfd->flags & EXEC_P)
{
/* Parts of the exec header will be filled in later, so
delay writing the header itself. Just leave space for
it. */
current_offset += sizeof (struct som_exec_auxhdr);
obj_som_file_hdr (abfd)->aux_header_size += sizeof (struct som_exec_auxhdr);
}
if (obj_som_version_hdr (abfd) != NULL) if (obj_som_version_hdr (abfd) != NULL)
{ {
unsigned int len; unsigned int len;
@ -3251,7 +3255,7 @@ som_build_and_write_symbol_table (abfd)
to hold the symbol table as we build it. */ to hold the symbol table as we build it. */
symtab_size = num_syms * sizeof (struct symbol_dictionary_record); symtab_size = num_syms * sizeof (struct symbol_dictionary_record);
som_symtab = (struct symbol_dictionary_record *) malloc (symtab_size); som_symtab = (struct symbol_dictionary_record *) malloc (symtab_size);
if (som_symtab == NULL) if (som_symtab == NULL && symtab_size != 0)
{ {
bfd_set_error (bfd_error_no_memory); bfd_set_error (bfd_error_no_memory);
goto error_return; goto error_return;
@ -3434,7 +3438,7 @@ som_slurp_symbol_table (abfd)
/* Read in the external SOM representation. */ /* Read in the external SOM representation. */
buf = malloc (symbol_count * symsize); buf = malloc (symbol_count * symsize);
if (buf == NULL) if (buf == NULL && symbol_count * symsize != 0)
{ {
bfd_set_error (bfd_error_no_memory); bfd_set_error (bfd_error_no_memory);
goto error_return; goto error_return;
@ -3550,9 +3554,15 @@ som_slurp_symbol_table (abfd)
} }
/* Mark section symbols and symbols used by the debugger. */ /* Mark section symbols and symbols used by the debugger. */
if (!strcmp (sym->symbol.name, "L$0\002")) if (sym->symbol.name[0] == '$'
&& sym->symbol.name[strlen (sym->symbol.name) - 1] == '$')
sym->symbol.flags |= BSF_SECTION_SYM; sym->symbol.flags |= BSF_SECTION_SYM;
else if (!strncmp (sym->symbol.name, "L$0", 3)) else if (!strncmp (sym->symbol.name, "L$0\002", 4))
{
sym->symbol.flags |= BSF_SECTION_SYM;
sym->symbol.name = sym->symbol.section->name;
}
else if (!strncmp (sym->symbol.name, "L$0\001", 4))
sym->symbol.flags |= BSF_DEBUGGING; sym->symbol.flags |= BSF_DEBUGGING;
/* Note increment at bottom of loop, since we skip some symbols /* Note increment at bottom of loop, since we skip some symbols
@ -4343,7 +4353,7 @@ som_bfd_count_ar_symbols (abfd, lst_header, count)
hash_table = hash_table =
(unsigned int *) malloc (lst_header->hash_size * sizeof (unsigned int)); (unsigned int *) malloc (lst_header->hash_size * sizeof (unsigned int));
if (hash_table == NULL) if (hash_table == NULL && lst_header->hash_size != 0)
{ {
bfd_set_error (bfd_error_no_memory); bfd_set_error (bfd_error_no_memory);
goto error_return; goto error_return;
@ -4436,7 +4446,7 @@ som_bfd_fill_in_ar_symbols (abfd, lst_header, syms)
hash_table = hash_table =
(unsigned int *) malloc (lst_header->hash_size * sizeof (unsigned int)); (unsigned int *) malloc (lst_header->hash_size * sizeof (unsigned int));
if (hash_table == NULL) if (hash_table == NULL && lst_header->hash_size != 0)
{ {
bfd_set_error (bfd_error_no_memory); bfd_set_error (bfd_error_no_memory);
goto error_return; goto error_return;
@ -4445,7 +4455,7 @@ som_bfd_fill_in_ar_symbols (abfd, lst_header, syms)
som_dict = som_dict =
(struct som_entry *) malloc (lst_header->module_count (struct som_entry *) malloc (lst_header->module_count
* sizeof (struct som_entry)); * sizeof (struct som_entry));
if (som_dict == NULL) if (som_dict == NULL && lst_header->module_count != 0)
{ {
bfd_set_error (bfd_error_no_memory); bfd_set_error (bfd_error_no_memory);
goto error_return; goto error_return;
@ -4823,7 +4833,7 @@ som_bfd_ar_write_symbol_stuff (abfd, nsyms, string_size, lst)
hash_table = hash_table =
(unsigned int *) malloc (lst.hash_size * sizeof (unsigned int)); (unsigned int *) malloc (lst.hash_size * sizeof (unsigned int));
if (hash_table == NULL) if (hash_table == NULL && lst.hash_size != 0)
{ {
bfd_set_error (bfd_error_no_memory); bfd_set_error (bfd_error_no_memory);
goto error_return; goto error_return;
@ -4831,7 +4841,7 @@ som_bfd_ar_write_symbol_stuff (abfd, nsyms, string_size, lst)
som_dict = som_dict =
(struct som_entry *) malloc (lst.module_count (struct som_entry *) malloc (lst.module_count
* sizeof (struct som_entry)); * sizeof (struct som_entry));
if (som_dict == NULL) if (som_dict == NULL && lst.module_count != 0)
{ {
bfd_set_error (bfd_error_no_memory); bfd_set_error (bfd_error_no_memory);
goto error_return; goto error_return;
@ -4840,7 +4850,7 @@ som_bfd_ar_write_symbol_stuff (abfd, nsyms, string_size, lst)
last_hash_entry = last_hash_entry =
((struct lst_symbol_record **) ((struct lst_symbol_record **)
malloc (lst.hash_size * sizeof (struct lst_symbol_record *))); malloc (lst.hash_size * sizeof (struct lst_symbol_record *)));
if (last_hash_entry == NULL) if (last_hash_entry == NULL && lst.hash_size != 0)
{ {
bfd_set_error (bfd_error_no_memory); bfd_set_error (bfd_error_no_memory);
goto error_return; goto error_return;
@ -4868,13 +4878,13 @@ som_bfd_ar_write_symbol_stuff (abfd, nsyms, string_size, lst)
/* FIXME should be done with buffers just like everything else... */ /* FIXME should be done with buffers just like everything else... */
lst_syms = malloc (nsyms * sizeof (struct lst_symbol_record)); lst_syms = malloc (nsyms * sizeof (struct lst_symbol_record));
if (lst_syms == NULL) if (lst_syms == NULL && nsyms != 0)
{ {
bfd_set_error (bfd_error_no_memory); bfd_set_error (bfd_error_no_memory);
goto error_return; goto error_return;
} }
strings = malloc (string_size); strings = malloc (string_size);
if (strings == NULL) if (strings == NULL && string_size != 0)
{ {
bfd_set_error (bfd_error_no_memory); bfd_set_error (bfd_error_no_memory);
goto error_return; goto error_return;