From 1dc1e0d965c141f653c2c8e5ab1ca3d7bd1f7630 Mon Sep 17 00:00:00 2001 From: Gunther Nikl Date: Wed, 29 Apr 2015 16:39:36 +0000 Subject: [PATCH] Add a helper function to read a 16-bit value. * bfd/amigaos.c (get_word): New helper function. (amiga_handle_rest): Use new helper function. (read_raw_relocs): Likewise. --- bfd/amigaos.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/bfd/amigaos.c b/bfd/amigaos.c index 15aef7e..fdbcdd5 100644 --- a/bfd/amigaos.c +++ b/bfd/amigaos.c @@ -161,6 +161,7 @@ typedef struct amiga_ardata_struct { #define MAX_NAME_SIZE 124 static bfd_boolean get_long PARAMS ((bfd *, unsigned long *)); +static bfd_boolean get_word PARAMS ((bfd *, unsigned long *)); static const struct bfd_target *amiga_object_p PARAMS ((bfd *)); static sec_ptr amiga_get_section_by_hunk_number PARAMS ((bfd *, long)); static bfd_boolean amiga_add_reloc PARAMS ((bfd *, sec_ptr, bfd_size_type, @@ -297,6 +298,17 @@ get_long (abfd, n) return TRUE; } +static bfd_boolean +get_word (abfd, n) + bfd *abfd; + unsigned long *n; +{ + if (bfd_bread ((PTR)n, 2, abfd) != 2) + return FALSE; + *n = GW (n); + return TRUE; +} + static const struct bfd_target * amiga_object_p (abfd) bfd *abfd; @@ -1049,10 +1061,9 @@ amiga_handle_rest (abfd, current_section, isload) } else { for (;;) { - char buf[2]; - if (bfd_bread (buf, 2, abfd) != 2) + if (!get_word (abfd, &no)) return FALSE; - if (no=GW(buf),!no) + if (!no) break; relp->num += no; if (bfd_seek (abfd, (no+1)<<1, SEEK_CUR)) @@ -2513,21 +2524,18 @@ read_raw_relocs (abfd, section, d_offset, count) case HUNK_RELOC32SHORT: /* read reloc count, hunk number and offsets */ for (howto=&howto_table[R_ABS32SHORT];;) { - char buf[2]; - if (bfd_bread (buf, 2, abfd) != 2) + /* read offsets and hunk number */ + if (!get_word (abfd, &no)) return FALSE; - if (no=GW(buf),!no) + if (!no) break; count -= no; - if (bfd_bread (buf, 2, abfd) != 2) + if (!get_word (abfd, &hunk_number)) return FALSE; - hunk_number = GW (buf); /* add relocs */ for (j=0; j