[binutils-gdb] windres_get_* functions

Alan Modra amodra@sourceware.org
Tue May 6 07:39:43 GMT 2025


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

commit a7cae7faf146227fdbffde6d5fed68417fc4120f
Author: Alan Modra <amodra@gmail.com>
Date:   Fri May 2 12:42:32 2025 +0930

    windres_get_* functions
    
    windres_get_32 and similar have a length parameter that in most cases
    is just the required length, so it is redundant.  The few cases where
    a variable length is passed are all in resrc.c.  So, get rid of the
    length parameter and introduce wrappers in resrc.c to check the
    length.

Diff:
---
 binutils/resbin.c  | 188 ++++++++++++++++++++++-----------------------
 binutils/rescoff.c |  32 ++++----
 binutils/resrc.c   | 221 +++++++++++++++++++++++++++++------------------------
 binutils/resres.c  |  22 +++---
 binutils/windint.h |   6 +-
 binutils/windres.c |  37 +++------
 6 files changed, 254 insertions(+), 252 deletions(-)

diff --git a/binutils/resbin.c b/binutils/resbin.c
index 98dd68b6fff..01046ec3f91 100644
--- a/binutils/resbin.c
+++ b/binutils/resbin.c
@@ -136,7 +136,7 @@ get_unicode (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length,
 	  toosmall (_("null terminated unicode string"));
 	  return NULL;
 	}
-      if (windres_get_16 (wrbfd, data + c * 2, 2) == 0)
+      if (windres_get_16 (wrbfd, data + c * 2) == 0)
 	break;
       ++c;
     }
@@ -144,7 +144,7 @@ get_unicode (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length,
   ret = res_alloc ((c + 1) * sizeof (unichar));
 
   for (i = 0; i < c; i++)
-    ret[i] = windres_get_16 (wrbfd, data + i * 2, 2);
+    ret[i] = windres_get_16 (wrbfd, data + i * 2);
   ret[i] = 0;
 
   if (retlen != NULL)
@@ -167,7 +167,7 @@ get_resid (windres_bfd *wrbfd, rc_res_id *id, const bfd_byte *data,
       return -1;
     }
 
-  first = windres_get_16 (wrbfd, data, 2);
+  first = windres_get_16 (wrbfd, data);
   if (first == 0xffff)
     {
       if (length < 4)
@@ -176,7 +176,7 @@ get_resid (windres_bfd *wrbfd, rc_res_id *id, const bfd_byte *data,
 	  return -1;
 	}
       id->named = 0;
-      id->u.id = windres_get_16 (wrbfd, data + 2, 2);
+      id->u.id = windres_get_16 (wrbfd, data + 2);
       return 4;
     }
   else
@@ -221,8 +221,8 @@ bin_to_res_cursor (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
     }
 
   c = res_alloc (sizeof (rc_cursor));
-  c->xhotspot = windres_get_16 (wrbfd, data, 2);
-  c->yhotspot = windres_get_16 (wrbfd, data + 2, 2);
+  c->xhotspot = windres_get_16 (wrbfd, data);
+  c->yhotspot = windres_get_16 (wrbfd, data + 2);
   c->length = length - 4;
   c->data = data + 4;
 
@@ -254,7 +254,7 @@ bin_to_res_menu (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length)
       return NULL;
     }
 
-  version = windres_get_16 (wrbfd, data, 2);
+  version = windres_get_16 (wrbfd, data);
 
   if (version == 0)
     {
@@ -277,8 +277,8 @@ bin_to_res_menu (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length)
 	  toosmall (_("menuex header"));
 	  return NULL;
 	}
-      m->help = windres_get_32 (wrbfd, data + 4, 4);
-      offset = windres_get_16 (wrbfd, data + 2, 2);
+      m->help = windres_get_32 (wrbfd, data + 4);
+      offset = windres_get_16 (wrbfd, data + 2);
       if (offset + 4 >= length)
 	{
 	  toosmall (_("menuex offset"));
@@ -327,7 +327,7 @@ bin_to_res_menuitems (windres_bfd *wrbfd, const bfd_byte *data,
       mi->state = 0;
       mi->help = 0;
 
-      flags = windres_get_16 (wrbfd, data, 2);
+      flags = windres_get_16 (wrbfd, data);
       mi->type = flags &~ (MENUITEM_POPUP | MENUITEM_ENDMENU);
 
       if ((flags & MENUITEM_POPUP) == 0)
@@ -341,7 +341,7 @@ bin_to_res_menuitems (windres_bfd *wrbfd, const bfd_byte *data,
 	  return NULL;
 	}
 
-      if (windres_get_16 (wrbfd, data + stroff, 2) == 0)
+      if (windres_get_16 (wrbfd, data + stroff) == 0)
 	{
 	  slen = 0;
 	  mi->text = NULL;
@@ -358,7 +358,7 @@ bin_to_res_menuitems (windres_bfd *wrbfd, const bfd_byte *data,
       if ((flags & MENUITEM_POPUP) == 0)
 	{
 	  mi->popup = NULL;
-	  mi->id = windres_get_16 (wrbfd, data + 2, 2);
+	  mi->id = windres_get_16 (wrbfd, data + 2);
 	}
       else
 	{
@@ -413,13 +413,13 @@ bin_to_res_menuexitems (windres_bfd *wrbfd, const bfd_byte *data,
 	}
 
       mi = res_alloc (sizeof (rc_menuitem));
-      mi->type = windres_get_32 (wrbfd, data, 4);
-      mi->state = windres_get_32 (wrbfd, data + 4, 4);
-      mi->id = windres_get_32 (wrbfd, data + 8, 4);
+      mi->type = windres_get_32 (wrbfd, data);
+      mi->state = windres_get_32 (wrbfd, data + 4);
+      mi->id = windres_get_32 (wrbfd, data + 8);
 
-      flags = windres_get_16 (wrbfd, data + 12, 2);
+      flags = windres_get_16 (wrbfd, data + 12);
 
-      if (windres_get_16 (wrbfd, data + 14, 2) == 0)
+      if (windres_get_16 (wrbfd, data + 14) == 0)
 	{
 	  slen = 0;
 	  mi->text = NULL;
@@ -448,7 +448,7 @@ bin_to_res_menuexitems (windres_bfd *wrbfd, const bfd_byte *data,
 	      toosmall (_("menuitem"));
 	      return NULL;
 	    }
-	  mi->help = windres_get_32 (wrbfd, data + itemlen, 4);
+	  mi->help = windres_get_32 (wrbfd, data + itemlen);
 	  itemlen += 4;
 
 	  mi->popup = bin_to_res_menuexitems (wrbfd, data + itemlen,
@@ -494,19 +494,19 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
 
   d = res_alloc (sizeof (rc_dialog));
 
-  signature = windres_get_16 (wrbfd, data + 2, 2);
+  signature = windres_get_16 (wrbfd, data + 2);
   if (signature != 0xffff)
     {
       d->ex = NULL;
-      d->style = windres_get_32 (wrbfd, data, 4);
-      d->exstyle = windres_get_32 (wrbfd, data + 4, 4);
+      d->style = windres_get_32 (wrbfd, data);
+      d->exstyle = windres_get_32 (wrbfd, data + 4);
       off = 8;
     }
   else
     {
       int version;
 
-      version = windres_get_16 (wrbfd, data, 2);
+      version = windres_get_16 (wrbfd, data);
       if (version != 1)
 	{
 	  non_fatal (_("unexpected DIALOGEX version %d"), version);
@@ -514,9 +514,9 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
 	}
 
       d->ex = res_alloc (sizeof (rc_dialog_ex));
-      d->ex->help = windres_get_32 (wrbfd, data + 4, 4);
-      d->exstyle = windres_get_32 (wrbfd, data + 8, 4);
-      d->style = windres_get_32 (wrbfd, data + 12, 4);
+      d->ex->help = windres_get_32 (wrbfd, data + 4);
+      d->exstyle = windres_get_32 (wrbfd, data + 8);
+      d->style = windres_get_32 (wrbfd, data + 12);
       off = 16;
     }
 
@@ -526,11 +526,11 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
       return NULL;
     }
 
-  c = windres_get_16 (wrbfd, data + off, 2);
-  d->x = windres_get_16 (wrbfd, data + off + 2, 2);
-  d->y = windres_get_16 (wrbfd, data + off + 4, 2);
-  d->width = windres_get_16 (wrbfd, data + off + 6, 2);
-  d->height = windres_get_16 (wrbfd, data + off + 8, 2);
+  c = windres_get_16 (wrbfd, data + off);
+  d->x = windres_get_16 (wrbfd, data + off + 2);
+  d->y = windres_get_16 (wrbfd, data + off + 4);
+  d->width = windres_get_16 (wrbfd, data + off + 6);
+  d->height = windres_get_16 (wrbfd, data + off + 8);
 
   off += 10;
 
@@ -570,7 +570,7 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
 	  return NULL;
 	}
 
-      d->pointsize = windres_get_16 (wrbfd, data + off, 2);
+      d->pointsize = windres_get_16 (wrbfd, data + off);
       off += 2;
 
       if (d->ex != NULL)
@@ -580,9 +580,9 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
 	      toosmall (_("dialogex font information"));
 	      return NULL;
 	    }
-	  d->ex->weight = windres_get_16 (wrbfd, data + off, 2);
-	  d->ex->italic = windres_get_8 (wrbfd, data + off + 2, 1);
-	  d->ex->charset = windres_get_8 (wrbfd, data + off + 3, 1);
+	  d->ex->weight = windres_get_16 (wrbfd, data + off);
+	  d->ex->italic = windres_get_8 (wrbfd, data + off + 2);
+	  d->ex->charset = windres_get_8 (wrbfd, data + off + 3);
 	  off += 4;
 	}
 
@@ -612,8 +612,8 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
 	      return NULL;
 	    }
 
-	  dc->style = windres_get_32 (wrbfd, data + off, 4);
-	  dc->exstyle = windres_get_32 (wrbfd, data + off + 4, 4);
+	  dc->style = windres_get_32 (wrbfd, data + off);
+	  dc->exstyle = windres_get_32 (wrbfd, data + off + 4);
 	  dc->help = 0;
 	  off += 8;
 	}
@@ -624,9 +624,9 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
 	      toosmall (_("dialogex control"));
 	      return NULL;
 	    }
-	  dc->help = windres_get_32 (wrbfd, data + off, 4);
-	  dc->exstyle = windres_get_32 (wrbfd, data + off + 4, 4);
-	  dc->style = windres_get_32 (wrbfd, data + off + 8, 4);
+	  dc->help = windres_get_32 (wrbfd, data + off);
+	  dc->exstyle = windres_get_32 (wrbfd, data + off + 4);
+	  dc->style = windres_get_32 (wrbfd, data + off + 8);
 	  off += 12;
 	}
 
@@ -636,15 +636,15 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
 	  return NULL;
 	}
 
-      dc->x = windres_get_16 (wrbfd, data + off, 2);
-      dc->y = windres_get_16 (wrbfd, data + off + 2, 2);
-      dc->width = windres_get_16 (wrbfd, data + off + 4, 2);
-      dc->height = windres_get_16 (wrbfd, data + off + 6, 2);
+      dc->x = windres_get_16 (wrbfd, data + off);
+      dc->y = windres_get_16 (wrbfd, data + off + 2);
+      dc->width = windres_get_16 (wrbfd, data + off + 4);
+      dc->height = windres_get_16 (wrbfd, data + off + 6);
 
       if (d->ex != NULL)
-	dc->id = windres_get_32 (wrbfd, data + off + 8, 4);
+	dc->id = windres_get_32 (wrbfd, data + off + 8);
       else
-	dc->id = windres_get_16 (wrbfd, data + off + 8, 2);
+	dc->id = windres_get_16 (wrbfd, data + off + 8);
 
       off += 10 + (d->ex != NULL ? 2 : 0);
 
@@ -664,7 +664,7 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
 	  return NULL;
 	}
 
-      datalen = windres_get_16 (wrbfd, data + off, 2);
+      datalen = windres_get_16 (wrbfd, data + off);
       off += 2;
 
       if (datalen == 0)
@@ -718,7 +718,7 @@ bin_to_res_string (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
 	  toosmall (_("stringtable string length"));
 	  return NULL;
 	}
-      slen = windres_get_16 (wrbfd, data, 2);
+      slen = windres_get_16 (wrbfd, data);
       st->strings[i].length = slen;
 
       if (slen > 0)
@@ -736,7 +736,7 @@ bin_to_res_string (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
 	  st->strings[i].string = s;
 
 	  for (j = 0; j < slen; j++)
-	    s[j] = windres_get_16 (wrbfd, data + 2 + j * 2, 2);
+	    s[j] = windres_get_16 (wrbfd, data + 2 + j * 2);
 	}
 
       data += 2 + 2 * slen;
@@ -766,7 +766,7 @@ bin_to_res_fontdir (windres_bfd *wrbfd, const bfd_byte *data,
       return NULL;
     }
 
-  c = windres_get_16 (wrbfd, data, 2);
+  c = windres_get_16 (wrbfd, data);
 
   first = NULL;
   pp = &first;
@@ -785,7 +785,7 @@ bin_to_res_fontdir (windres_bfd *wrbfd, const bfd_byte *data,
 
       bfi = (const struct bin_fontdir_item *) data;
       fd = res_alloc (sizeof *fd);
-      fd->index = windres_get_16 (wrbfd, bfi->index, 2);
+      fd->index = windres_get_16 (wrbfd, bfi->index);
 
       /* To work out the length of the fontdir data, we must get the
          length of the device name and face name strings, even though
@@ -858,9 +858,9 @@ bin_to_res_accelerators (windres_bfd *wrbfd, const bfd_byte *data,
 
       a = res_alloc (sizeof (rc_accelerator));
 
-      a->flags = windres_get_16 (wrbfd, data, 2);
-      a->key = windres_get_16 (wrbfd, data + 2, 2);
-      a->id = windres_get_16 (wrbfd, data + 4, 2);
+      a->flags = windres_get_16 (wrbfd, data);
+      a->key = windres_get_16 (wrbfd, data + 2);
+      a->id = windres_get_16 (wrbfd, data + 4);
 
       a->next = NULL;
       *pp = a;
@@ -919,14 +919,14 @@ bin_to_res_group_cursor (windres_bfd *wrbfd, const bfd_byte *data,
       return NULL;
     }
 
-  type = windres_get_16 (wrbfd, data + 2, 2);
+  type = windres_get_16 (wrbfd, data + 2);
   if (type != 2)
     {
       non_fatal (_("unexpected group cursor type %d"), type);
       return NULL;
     }
 
-  c = windres_get_16 (wrbfd, data + 4, 2);
+  c = windres_get_16 (wrbfd, data + 4);
 
   data += 6;
   length -= 6;
@@ -946,12 +946,12 @@ bin_to_res_group_cursor (windres_bfd *wrbfd, const bfd_byte *data,
 
       gc = res_alloc (sizeof *gc);
 
-      gc->width = windres_get_16 (wrbfd, data, 2);
-      gc->height = windres_get_16 (wrbfd, data + 2, 2);
-      gc->planes = windres_get_16 (wrbfd, data + 4, 2);
-      gc->bits = windres_get_16 (wrbfd, data + 6, 2);
-      gc->bytes = windres_get_32 (wrbfd, data + 8, 4);
-      gc->index = windres_get_16 (wrbfd, data + 12, 2);
+      gc->width = windres_get_16 (wrbfd, data);
+      gc->height = windres_get_16 (wrbfd, data + 2);
+      gc->planes = windres_get_16 (wrbfd, data + 4);
+      gc->bits = windres_get_16 (wrbfd, data + 6);
+      gc->bytes = windres_get_32 (wrbfd, data + 8);
+      gc->index = windres_get_16 (wrbfd, data + 12);
 
       gc->next = NULL;
       *pp = gc;
@@ -984,14 +984,14 @@ bin_to_res_group_icon (windres_bfd *wrbfd, const bfd_byte *data,
       return NULL;
     }
 
-  type = windres_get_16 (wrbfd, data + 2, 2);
+  type = windres_get_16 (wrbfd, data + 2);
   if (type != 1)
     {
       non_fatal (_("unexpected group icon type %d"), type);
       return NULL;
     }
 
-  c = windres_get_16 (wrbfd, data + 4, 2);
+  c = windres_get_16 (wrbfd, data + 4);
 
   data += 6;
   length -= 6;
@@ -1011,13 +1011,13 @@ bin_to_res_group_icon (windres_bfd *wrbfd, const bfd_byte *data,
 
       gi = res_alloc (sizeof (rc_group_icon));
 
-      gi->width = windres_get_8 (wrbfd, data, 1);
-      gi->height = windres_get_8 (wrbfd, data + 1, 1);
-      gi->colors = windres_get_8 (wrbfd, data + 2, 1);
-      gi->planes = windres_get_16 (wrbfd, data + 4, 2);
-      gi->bits = windres_get_16 (wrbfd, data + 6, 2);
-      gi->bytes = windres_get_32 (wrbfd, data + 8, 4);
-      gi->index = windres_get_16 (wrbfd, data + 12, 2);
+      gi->width = windres_get_8 (wrbfd, data);
+      gi->height = windres_get_8 (wrbfd, data + 1);
+      gi->colors = windres_get_8 (wrbfd, data + 2);
+      gi->planes = windres_get_16 (wrbfd, data + 4);
+      gi->bits = windres_get_16 (wrbfd, data + 6);
+      gi->bytes = windres_get_32 (wrbfd, data + 8);
+      gi->index = windres_get_16 (wrbfd, data + 12);
 
       gi->next = NULL;
       *pp = gi;
@@ -1051,9 +1051,9 @@ get_version_header (windres_bfd *wrbfd, const bfd_byte *data,
       return false;
     }
 
-  *len = (windres_get_16 (wrbfd, data, 2) + 3) & ~3;
-  *vallen = windres_get_16 (wrbfd, data + 2, 2);
-  *type = windres_get_16 (wrbfd, data + 4, 2);
+  *len = (windres_get_16 (wrbfd, data) + 3) & ~3;
+  *vallen = windres_get_16 (wrbfd, data + 2);
+  *type = windres_get_16 (wrbfd, data + 4);
 
   *off = 6;
 
@@ -1078,7 +1078,7 @@ get_version_header (windres_bfd *wrbfd, const bfd_byte *data,
 	      toosmall (key);
 	      return false;
 	    }
-	  if (windres_get_16 (wrbfd, data, 2) != (bfd_byte) *key)
+	  if (windres_get_16 (wrbfd, data) != (bfd_byte) *key)
 	    {
 	      non_fatal (_("unexpected version string"));
 	      return false;
@@ -1155,14 +1155,14 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data,
 	  return NULL;
 	}
 
-      signature = windres_get_32 (wrbfd, data, 4);
+      signature = windres_get_32 (wrbfd, data);
       if (signature != 0xfeef04bd)
 	{
 	  non_fatal (_("unexpected fixed version signature %lu"), signature);
 	  return NULL;
 	}
 
-      fiv = windres_get_32 (wrbfd, data + 4, 4);
+      fiv = windres_get_32 (wrbfd, data + 4);
       if (fiv != 0 && fiv != 0x10000)
 	{
 	  non_fatal (_("unexpected fixed version info version %lu"), fiv);
@@ -1171,17 +1171,17 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data,
 
       fi = res_alloc (sizeof (rc_fixed_versioninfo));
 
-      fi->file_version_ms = windres_get_32 (wrbfd, data + 8, 4);
-      fi->file_version_ls = windres_get_32 (wrbfd, data + 12, 4);
-      fi->product_version_ms = windres_get_32 (wrbfd, data + 16, 4);
-      fi->product_version_ls = windres_get_32 (wrbfd, data + 20, 4);
-      fi->file_flags_mask = windres_get_32 (wrbfd, data + 24, 4);
-      fi->file_flags = windres_get_32 (wrbfd, data + 28, 4);
-      fi->file_os = windres_get_32 (wrbfd, data + 32, 4);
-      fi->file_type = windres_get_32 (wrbfd, data + 36, 4);
-      fi->file_subtype = windres_get_32 (wrbfd, data + 40, 4);
-      fi->file_date_ms = windres_get_32 (wrbfd, data + 44, 4);
-      fi->file_date_ls = windres_get_32 (wrbfd, data + 48, 4);
+      fi->file_version_ms = windres_get_32 (wrbfd, data + 8);
+      fi->file_version_ls = windres_get_32 (wrbfd, data + 12);
+      fi->product_version_ms = windres_get_32 (wrbfd, data + 16);
+      fi->product_version_ls = windres_get_32 (wrbfd, data + 20);
+      fi->file_flags_mask = windres_get_32 (wrbfd, data + 24);
+      fi->file_flags = windres_get_32 (wrbfd, data + 28);
+      fi->file_os = windres_get_32 (wrbfd, data + 32);
+      fi->file_type = windres_get_32 (wrbfd, data + 36);
+      fi->file_subtype = windres_get_32 (wrbfd, data + 40);
+      fi->file_date_ms = windres_get_32 (wrbfd, data + 44);
+      fi->file_date_ls = windres_get_32 (wrbfd, data + 48);
 
       data += 52;
       length -= 52;
@@ -1203,7 +1203,7 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data,
 
       vi = res_alloc (sizeof (rc_ver_info));
 
-      ch = windres_get_16 (wrbfd, data + 6, 2);
+      ch = windres_get_16 (wrbfd, data + 6);
 
       if (ch == 'S')
 	{
@@ -1366,8 +1366,8 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data,
 
 	      vv = res_alloc (sizeof (rc_ver_varinfo));
 
-	      vv->language = windres_get_16 (wrbfd, data, 2);
-	      vv->charset = windres_get_16 (wrbfd, data + 2, 2);
+	      vv->language = windres_get_16 (wrbfd, data);
+	      vv->charset = windres_get_16 (wrbfd, data + 2);
 
 	      vv->next = NULL;
 	      *ppvv = vv;
@@ -1453,9 +1453,9 @@ bin_to_res_toolbar (windres_bfd *wrbfd, const bfd_byte *data,
       return NULL;
     }
   ri = res_alloc (sizeof (rc_toolbar));
-  ri->button_width = windres_get_32 (wrbfd, data, 4);
-  ri->button_height = windres_get_32 (wrbfd, data + 4, 4);
-  ri->nitems = windres_get_32 (wrbfd, data + 8, 4);
+  ri->button_width = windres_get_32 (wrbfd, data);
+  ri->button_height = windres_get_32 (wrbfd, data + 4);
+  ri->nitems = windres_get_32 (wrbfd, data + 8);
   ri->items = NULL;
 
   data += 12;
@@ -1470,7 +1470,7 @@ bin_to_res_toolbar (windres_bfd *wrbfd, const bfd_byte *data,
 	  toosmall (_("toolbar item"));
 	  return NULL;
 	}
-      it->id.u.id = (int) windres_get_32 (wrbfd, data, 4);
+      it->id.u.id = (int) windres_get_32 (wrbfd, data);
       it->prev = it->next = NULL;
       data += 4;
       length -= 4;
diff --git a/binutils/rescoff.c b/binutils/rescoff.c
index 60316021e95..14546a4b91c 100644
--- a/binutils/rescoff.c
+++ b/binutils/rescoff.c
@@ -232,14 +232,14 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
   erd = (const struct extern_res_directory *) data;
 
   rd = (rc_res_directory *) res_alloc (sizeof (rc_res_directory));
-  rd->characteristics = windres_get_32 (wrbfd, erd->characteristics, 4);
-  rd->time = windres_get_32 (wrbfd, erd->time, 4);
-  rd->major = windres_get_16 (wrbfd, erd->major, 2);
-  rd->minor = windres_get_16 (wrbfd, erd->minor, 2);
+  rd->characteristics = windres_get_32 (wrbfd, erd->characteristics);
+  rd->time = windres_get_32 (wrbfd, erd->time);
+  rd->major = windres_get_16 (wrbfd, erd->major);
+  rd->minor = windres_get_16 (wrbfd, erd->minor);
   rd->entries = NULL;
 
-  name_count = windres_get_16 (wrbfd, erd->name_count, 2);
-  id_count = windres_get_16 (wrbfd, erd->id_count, 2);
+  name_count = windres_get_16 (wrbfd, erd->name_count);
+  id_count = windres_get_16 (wrbfd, erd->id_count);
 
   pp = &rd->entries;
 
@@ -261,8 +261,8 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
 	  return NULL;
 	}
 
-      name = windres_get_32 (wrbfd, ere->name, 4);
-      rva = windres_get_32 (wrbfd, ere->rva, 4);
+      name = windres_get_32 (wrbfd, ere->name);
+      rva = windres_get_32 (wrbfd, ere->rva);
 
       /* For some reason the high bit in NAME is set.  */
       name &=~ 0x80000000;
@@ -279,7 +279,7 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
 	  overrun (flaginfo, _("resource name"));
 	  return NULL;
 	}
-      length = windres_get_16 (wrbfd, ers, 2);
+      length = windres_get_16 (wrbfd, ers);
       /* PR 17512: file: 05dc4a16.  */
       if (length * 2 + 4 > flaginfo->data_end - ers)
 	{
@@ -292,7 +292,7 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
       re->id.u.n.length = length;
       re->id.u.n.name = (unichar *) res_alloc (length * sizeof (unichar));
       for (j = 0; j < length; j++)
-	re->id.u.n.name[j] = windres_get_16 (wrbfd, ers + j * 2 + 2, 2);
+	re->id.u.n.name[j] = windres_get_16 (wrbfd, ers + j * 2 + 2);
 
       if (level == 0)
 	type = &re->id;
@@ -337,8 +337,8 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
 	  return NULL;
 	}
 
-      name = windres_get_32 (wrbfd, ere->name, 4);
-      rva = windres_get_32 (wrbfd, ere->rva, 4);
+      name = windres_get_32 (wrbfd, ere->name);
+      rva = windres_get_32 (wrbfd, ere->rva);
 
       re = (rc_res_entry *) res_alloc (sizeof *re);
       re->next = NULL;
@@ -405,8 +405,8 @@ read_coff_data_entry (windres_bfd *wrbfd, const bfd_byte *data,
 
   erd = (const struct extern_res_data *) data;
 
-  size = windres_get_32 (wrbfd, erd->size, 4);
-  rva = windres_get_32 (wrbfd, erd->rva, 4);
+  size = windres_get_32 (wrbfd, erd->size);
+  rva = windres_get_32 (wrbfd, erd->rva);
   if (rva < flaginfo->secaddr
       || rva - flaginfo->secaddr >= (rc_uint_type) (flaginfo->data_end - flaginfo->data))
     {
@@ -426,8 +426,8 @@ read_coff_data_entry (windres_bfd *wrbfd, const bfd_byte *data,
   if (r != NULL)
     {
       memset (&r->res_info, 0, sizeof (rc_res_res_info));
-      r->coff_info.codepage = windres_get_32 (wrbfd, erd->codepage, 4);
-      r->coff_info.reserved = windres_get_32 (wrbfd, erd->reserved, 4);
+      r->coff_info.codepage = windres_get_32 (wrbfd, erd->codepage);
+      r->coff_info.reserved = windres_get_32 (wrbfd, erd->reserved);
     }
 
   return r;
diff --git a/binutils/resrc.c b/binutils/resrc.c
index 8f9451b659c..4ab830f0108 100644
--- a/binutils/resrc.c
+++ b/binutils/resrc.c
@@ -299,7 +299,7 @@ run_cmd (char *cmd, const char *redir)
       if (WEXITSTATUS (wait_status) != 0)
 	{
 	  fatal (_("%s exited with status %d"), cmd,
-	         WEXITSTATUS (wait_status));
+		 WEXITSTATUS (wait_status));
 	  retcode = 1;
 	}
     }
@@ -331,7 +331,7 @@ open_input_stream (char *cmd)
 
       if (verbose)
 	fprintf (stderr,
-	         _("Using temporary file `%s' to read preprocessor output\n"),
+		 _("Using temporary file `%s' to read preprocessor output\n"),
 		 cpp_temp_file);
     }
   else
@@ -359,15 +359,15 @@ filename_need_quotes (const char *filename)
   while (*filename != 0)
     {
       switch (*filename)
-        {
-        case '&':
-        case ' ':
-        case '<':
-        case '>':
-        case '|':
-        case '%':
-          return 1;
-        }
+	{
+	case '&':
+	case ' ':
+	case '<':
+	case '>':
+	case '|':
+	case '%':
+	  return 1;
+	}
       ++filename;
     }
   return 0;
@@ -529,7 +529,7 @@ read_rc_file (const char *filename, const char *preprocessor,
       if (slash && ! cpp_pipe)
 	{
 	  /* Next, try looking for a gcc in the same directory as
-             that windres */
+	     that windres */
 
 	  cpp_pipe = look_for_default (cmd, program_name, slash - program_name + 1,
 				       preprocargs, filename);
@@ -586,11 +586,11 @@ close_input_stream (void)
   else
     {
       if (cpp_pipe != NULL)
-        {
+	{
 	  int err;
 	  err = pclose (cpp_pipe);
 	  /* We are reading from a pipe, therefore we don't
-             know if cpp failed or succeeded until pclose.  */
+	     know if cpp failed or succeeded until pclose.  */
 	  if (err != 0 || errno == ECHILD)
 	    {
 	      /* Since this is also run via xatexit, safeguard.  */
@@ -598,7 +598,7 @@ close_input_stream (void)
 	      cpp_temp_file = NULL;
 	      fatal (_("preprocessing failed."));
 	    }
-        }
+	}
     }
 
   /* Since this is also run via xatexit, safeguard.  */
@@ -679,6 +679,22 @@ get_data (FILE *e, bfd_byte *p, rc_uint_type c, const char *msg)
   fatal (_("%s: read of %lu returned %lu"),
 	 msg, (unsigned long) c, (unsigned long) got);
 }
+
+static rc_uint_type
+target_get_16 (const void *p, size_t len)
+{
+  if (len < 2)
+    fatal (_("not enough data"));
+  return windres_get_16 (&wrtarget, p);
+}
+
+static rc_uint_type
+target_get_32 (const void *p, size_t len)
+{
+  if (len < 4)
+    fatal (_("not enough data"));
+  return windres_get_32 (&wrtarget, p);
+}
 

 /* Define an accelerator resource.  */
 
@@ -1094,7 +1110,7 @@ define_fontdir_rcdata (rc_res_id id,const rc_res_res_info *resinfo,
   if (pb_data)
     {
       rc_uint_type off = 2;
-      c = windres_get_16 (&wrtarget, pb_data, len_data);
+      c = target_get_16 (pb_data, len_data);
       for (; c > 0; c--)
 	{
 	  size_t len;
@@ -1103,7 +1119,7 @@ define_fontdir_rcdata (rc_res_id id,const rc_res_res_info *resinfo,
 
 	  bfi = (const struct bin_fontdir_item *) pb_data + off;
 	  fd = (rc_fontdir *) res_alloc (sizeof (rc_fontdir));
-	  fd->index = windres_get_16 (&wrtarget, bfi->index, len_data - off);
+	  fd->index = target_get_16 (bfi->index, len_data - off);
 	  fd->data = pb_data + off;
 	  off += 56;
 	  len = strlen ((char *) bfi->device_name) + 1;
@@ -1230,8 +1246,8 @@ define_icon (rc_res_id id, const rc_res_res_info *resinfo,
       rc_group_icon *cg;
 
       /* For some reason, at least in some files the planes and bits
-         are zero.  We instead set them from the color.  This is
-         copied from rcl.  */
+	 are zero.  We instead set them from the color.  This is
+	 copied from rcl.  */
 
       cg = (rc_group_icon *) res_alloc (sizeof (rc_group_icon));
       cg->next = NULL;
@@ -1288,10 +1304,10 @@ define_group_icon_rcdata (rc_res_id id, const rc_res_res_info *resinfo,
     {
       int c, i;
       unsigned short type;
-      type = windres_get_16 (&wrtarget, pb_data + 2, len_data - 2);
+      type = target_get_16 (pb_data + 2, len_data - 2);
       if (type != 1)
 	fatal (_("unexpected group icon type %d"), type);
-      c = windres_get_16 (&wrtarget, pb_data + 4, len_data - 4);
+      c = target_get_16 (pb_data + 4, len_data - 4);
       len_data -= 6;
       pb_data += 6;
 
@@ -1304,10 +1320,10 @@ define_group_icon_rcdata (rc_res_id id, const rc_res_res_info *resinfo,
 	  cg->width = pb_data[0];
 	  cg->height = pb_data[1];
 	  cg->colors = pb_data[2];
-	  cg->planes = windres_get_16 (&wrtarget, pb_data + 4, len_data - 4);
-	  cg->bits =  windres_get_16 (&wrtarget, pb_data + 6, len_data - 6);
-	  cg->bytes = windres_get_32 (&wrtarget, pb_data + 8, len_data - 8);
-	  cg->index = windres_get_16 (&wrtarget, pb_data + 12, len_data - 12);
+	  cg->planes = target_get_16 (pb_data + 4, len_data - 4);
+	  cg->bits =  target_get_16 (pb_data + 6, len_data - 6);
+	  cg->bytes = target_get_32 (pb_data + 8, len_data - 8);
+	  cg->index = target_get_16 (pb_data + 12, len_data - 12);
 	  if (! first)
 	    first = cg;
 	  else
@@ -1341,10 +1357,10 @@ define_group_cursor_rcdata (rc_res_id id, const rc_res_res_info *resinfo,
     {
       int c, i;
       unsigned short type;
-      type = windres_get_16 (&wrtarget, pb_data + 2, len_data - 2);
+      type = target_get_16 (pb_data + 2, len_data - 2);
       if (type != 2)
 	fatal (_("unexpected group cursor type %d"), type);
-      c = windres_get_16 (&wrtarget, pb_data + 4, len_data - 4);
+      c = target_get_16 (pb_data + 4, len_data - 4);
       len_data -= 6;
       pb_data += 6;
 
@@ -1354,12 +1370,12 @@ define_group_cursor_rcdata (rc_res_id id, const rc_res_res_info *resinfo,
 	    fatal ("too small group icon rcdata");
 	  cg = (rc_group_cursor *) res_alloc (sizeof (rc_group_cursor));
 	  cg->next = NULL;
-	  cg->width = windres_get_16 (&wrtarget, pb_data, len_data);
-	  cg->height = windres_get_16 (&wrtarget, pb_data + 2, len_data - 2);
-	  cg->planes = windres_get_16 (&wrtarget, pb_data + 4, len_data - 4);
-	  cg->bits =  windres_get_16 (&wrtarget, pb_data + 6, len_data - 6);
-	  cg->bytes = windres_get_32 (&wrtarget, pb_data + 8, len_data - 8);
-	  cg->index = windres_get_16 (&wrtarget, pb_data + 12, len_data - 12);
+	  cg->width = target_get_16 (pb_data, len_data);
+	  cg->height = target_get_16 (pb_data + 2, len_data - 2);
+	  cg->planes = target_get_16 (pb_data + 4, len_data - 4);
+	  cg->bits =  target_get_16 (pb_data + 6, len_data - 6);
+	  cg->bytes = target_get_32 (pb_data + 8, len_data - 8);
+	  cg->index = target_get_16 (pb_data + 12, len_data - 12);
 	  if (! first)
 	    first = cg;
 	  else
@@ -1389,8 +1405,8 @@ define_cursor_rcdata (rc_res_id id, const rc_res_res_info *resinfo,
   pb_data = rcdata_render_as_buffer (data, &len_data);
 
   c = (rc_cursor *) res_alloc (sizeof (rc_cursor));
-  c->xhotspot = windres_get_16 (&wrtarget, pb_data, len_data);
-  c->yhotspot = windres_get_16 (&wrtarget, pb_data + 2, len_data - 2);
+  c->xhotspot = target_get_16 (pb_data, len_data);
+  c->yhotspot = target_get_16 (pb_data + 2, len_data - 2);
   c->length = len_data - BIN_CURSOR_SIZE;
   c->data = (const bfd_byte *) (data + BIN_CURSOR_SIZE);
 
@@ -1994,9 +2010,9 @@ write_rc_directory (FILE *e, const rc_res_directory *rd,
 	{
 	case 1:
 	  /* If we're at level 1, the key of this resource is the
-             type.  This normally duplicates the information we have
-             stored with the resource itself, but we need to remember
-             the type if this is a user define resource type.  */
+	     type.  This normally duplicates the information we have
+	     stored with the resource itself, but we need to remember
+	     the type if this is a user define resource type.  */
 	  type = &re->id;
 	  break;
 
@@ -2031,10 +2047,10 @@ write_rc_directory (FILE *e, const rc_res_directory *rd,
 	  if (level == 3)
 	    {
 	      /* This is the normal case: the three levels are
-                 TYPE/NAME/LANGUAGE.  NAME will have been set at level
-                 2, and represents the name to use.  We probably just
-                 set LANGUAGE, and it will probably match what the
-                 resource itself records if anything.  */
+		 TYPE/NAME/LANGUAGE.  NAME will have been set at level
+		 2, and represents the name to use.  We probably just
+		 set LANGUAGE, and it will probably match what the
+		 resource itself records if anything.  */
 	      write_rc_resource (e, type, name, re->u.res, language);
 	    }
 	  else
@@ -2493,7 +2509,7 @@ write_rc_cursor (FILE *e, const rc_cursor *cursor)
 	   (unsigned int) cursor->xhotspot, (unsigned int) cursor->yhotspot,
 	   (int) cursor->xhotspot, (int) cursor->yhotspot);
   write_rc_datablock (e, (rc_uint_type) cursor->length, (const bfd_byte *) cursor->data,
-  		      0, 0, 0);
+		      0, 0, 0);
   fprintf (e, "END\n");
 }
 
@@ -2654,10 +2670,10 @@ write_rc_dialog_control (FILE *e, const rc_dialog_control *control)
   /* For EDITTEXT, COMBOBOX, LISTBOX, and SCROLLBAR don't dump text.  */
   if ((control->text.named || control->text.u.id != 0)
       && (!ci
-          || (ci->class != CTL_EDIT
-              && ci->class != CTL_COMBOBOX
-              && ci->class != CTL_LISTBOX
-              && ci->class != CTL_SCROLLBAR)))
+	  || (ci->class != CTL_EDIT
+	      && ci->class != CTL_COMBOBOX
+	      && ci->class != CTL_LISTBOX
+	      && ci->class != CTL_SCROLLBAR)))
     {
       fprintf (e, " ");
       res_id_print (e, control->text, 1);
@@ -2906,8 +2922,8 @@ test_rc_datablock_text (rc_uint_type length, const bfd_byte *data)
   for (i = 0, c = 0; i < length; i++)
     {
       if (! ISPRINT (data[i]) && data[i] != '\n'
-      	  && ! (data[i] == '\r' && (i + 1) < length && data[i + 1] == '\n')
-      	  && data[i] != '\t'
+	  && ! (data[i] == '\r' && (i + 1) < length && data[i + 1] == '\n')
+	  && data[i] != '\t'
 	  && ! (data[i] == 0 && (i + 1) != length))
 	{
 	  if (data[i] <= 7)
@@ -2944,7 +2960,7 @@ write_rc_messagetable (FILE *e, rc_uint_type length, const bfd_byte *data)
 	rc_uint_type m, i;
 
 	mt = (const struct bin_messagetable *) data;
-	m = windres_get_32 (&wrtarget, mt->cblocks, length);
+	m = target_get_32 (mt->cblocks, length);
 
 	if (length < (BIN_MESSAGETABLE_SIZE + m * BIN_MESSAGETABLE_BLOCK_SIZE))
 	  {
@@ -2956,9 +2972,9 @@ write_rc_messagetable (FILE *e, rc_uint_type length, const bfd_byte *data)
 	    rc_uint_type low, high, offset;
 	    const struct bin_messagetable_item *mti;
 
-	    low = windres_get_32 (&wrtarget, mt->items[i].lowid, 4);
-	    high = windres_get_32 (&wrtarget, mt->items[i].highid, 4);
-	    offset = windres_get_32 (&wrtarget, mt->items[i].offset, 4);
+	    low = windres_get_32 (&wrtarget, mt->items[i].lowid);
+	    high = windres_get_32 (&wrtarget, mt->items[i].highid);
+	    offset = windres_get_32 (&wrtarget, mt->items[i].offset);
 
 	    while (low <= high)
 	      {
@@ -2969,8 +2985,8 @@ write_rc_messagetable (FILE *e, rc_uint_type length, const bfd_byte *data)
 		    break;
 		  }
 		mti = (const struct bin_messagetable_item *) &data[offset];
-		elen = windres_get_16 (&wrtarget, mti->length, 2);
-		flags = windres_get_16 (&wrtarget, mti->flags, 2);
+		elen = windres_get_16 (&wrtarget, mti->length);
+		flags = windres_get_16 (&wrtarget, mti->flags);
 		if ((offset + elen) > length)
 		  {
 		    has_error = 1;
@@ -3008,8 +3024,8 @@ write_rc_messagetable (FILE *e, rc_uint_type length, const bfd_byte *data)
 }
 
 static void
-write_rc_datablock (FILE *e, rc_uint_type length, const bfd_byte *data, int has_next,
-		    int hasblock, int show_comment)
+write_rc_datablock (FILE *e, rc_uint_type length, const bfd_byte *data,
+		    int has_next, int hasblock, int show_comment)
 {
   int plen;
 
@@ -3031,23 +3047,23 @@ write_rc_datablock (FILE *e, rc_uint_type length, const bfd_byte *data, int has_
 	      if (i < length && data[i] == '\n')
 		++i, ++c;
 	      ascii_print(e, (const char *) &data[i - c], c);
-	    fprintf (e, "\"");
+	      fprintf (e, "\"");
 	      if (i < length)
 		fprintf (e, "\n");
 	    }
 
 	  if (i == 0)
-	      {
+	    {
 	      indent (e, 2);
 	      fprintf (e, "\"\"");
-	      }
+	    }
 	  if (has_next)
 	    fprintf (e, ",");
 	  fprintf (e, "\n");
 	  if (hasblock)
 	    fprintf (e, "END\n");
 	  return;
-	  }
+	}
       if (test_rc_datablock_unicode (length, data))
 	{
 	  rc_uint_type i, c;
@@ -3057,20 +3073,20 @@ write_rc_datablock (FILE *e, rc_uint_type length, const bfd_byte *data, int has_
 
 	      u = (const unichar *) &data[i];
 	      indent (e, 2);
-	  fprintf (e, "L\"");
+	      fprintf (e, "L\"");
 
 	      for (c = 0; i < length && c < 160 && u[c] != '\n'; c++, i += 2)
 		;
 	      if (i < length && u[c] == '\n')
 		i += 2, ++c;
 	      unicode_print (e, u, c);
-	  fprintf (e, "\"");
+	      fprintf (e, "\"");
 	      if (i < length)
 		fprintf (e, "\n");
 	    }
 
 	  if (i == 0)
-	  {
+	    {
 	      indent (e, 2);
 	      fprintf (e, "L\"\"");
 	    }
@@ -3086,14 +3102,14 @@ write_rc_datablock (FILE *e, rc_uint_type length, const bfd_byte *data, int has_
     }
 
   if (length != 0)
-	      {
+    {
       rc_uint_type i, max_row;
       int first = 1;
 
       max_row = (show_comment ? 4 : 8);
       indent (e, 2);
       for (i = 0; i + 3 < length;)
-		  {
+	{
 	  rc_uint_type k;
 	  rc_uint_type comment_start;
 
@@ -3103,65 +3119,68 @@ write_rc_datablock (FILE *e, rc_uint_type length, const bfd_byte *data, int has_
 	    indent (e, 2);
 
 	  for (k = 0; k < max_row && i + 3 < length; k++, i += 4)
-		      {
+	    {
 	      if (k == 0)
-		plen  = fprintf (e, "0x%lxL",
-				 (unsigned long) windres_get_32 (&wrtarget, data + i, length - i));
-			else
+		plen = fprintf (e, "0x%lxL",
+				(unsigned long) target_get_32 (data + i,
+							       length - i));
+	      else
 		plen = fprintf (e, " 0x%lxL",
-				(unsigned long) windres_get_32 (&wrtarget, data + i, length - i)) - 1;
+				(unsigned long) target_get_32 (data + i,
+							       length - i)) - 1;
 	      if (has_next || (i + 4) < length)
-			  {
+		{
 		  if (plen>0 && plen < 11)
 		    indent (e, 11 - plen);
 		  fprintf (e, ",");
-			  }
-		      }
+		}
+	    }
 	  if (show_comment)
 	    {
 	      fprintf (e, "\t/* ");
-	      ascii_print (e, (const char *) &data[comment_start], i - comment_start);
+	      ascii_print (e, (const char *) &data[comment_start],
+			   i - comment_start);
 	      fprintf (e, ".  */");
-		  }
-		fprintf (e, "\n");
-		first = 0;
-	      }
+	    }
+	  fprintf (e, "\n");
+	  first = 0;
+	}
 
       if (i + 1 < length)
-	      {
-		if (! first)
+	{
+	  if (! first)
 	    indent (e, 2);
 	  plen = fprintf (e, "0x%x",
-	  		  (int) windres_get_16 (&wrtarget, data + i, length - i));
+			  (int) target_get_16 (data + i, length - i));
 	  if (has_next || i + 2 < length)
-		  {
+	    {
 	      if (plen > 0 && plen < 11)
 		indent (e, 11 - plen);
 	      fprintf (e, ",");
-		      }
+	    }
 	  if (show_comment)
 	    {
 	      fprintf (e, "\t/* ");
 	      ascii_print (e, (const char *) &data[i], 2);
 	      fprintf (e, ".  */");
-		  }
-		fprintf (e, "\n");
-		i += 2;
-		first = 0;
-	      }
+	    }
+	  fprintf (e, "\n");
+	  i += 2;
+	  first = 0;
+	}
 
       if (i < length)
-	      {
-		if (! first)
+	{
+	  if (! first)
 	    indent (e, 2);
 	  fprintf (e, "\"");
 	  ascii_print (e, (const char *) &data[i], 1);
 	  fprintf (e, "\"");
 	  if (has_next)
-		  fprintf (e, ",");
-		fprintf (e, "\n");
-		first = 0;
-	      }
+	    fprintf (e, ",");
+	  fprintf (e, "\n");
+	  first = 0;
+	}
     }
   if (hasblock)
     fprintf (e, "END\n");
@@ -3214,9 +3233,9 @@ write_rc_rcdata (FILE *e, const rc_rcdata_item *rcdata, int ind)
 
 	case RCDATA_BUFFER:
 	  write_rc_datablock (e, (rc_uint_type) ri->u.buffer.length,
-	  		      (const bfd_byte *) ri->u.buffer.data,
-	    		      ri->next != NULL, 0, -1);
-	    break;
+			      (const bfd_byte *) ri->u.buffer.data,
+			      ri->next != NULL, 0, -1);
+	  break;
 	}
 
       if (ri->type != RCDATA_BUFFER)
@@ -3257,7 +3276,7 @@ write_rc_stringtable (FILE *e, const rc_res_id *name,
 	{
 	  fprintf (e, "  %lu, ", (unsigned long) offset + i);
 	  unicode_print_quoted (e, stringtable->strings[i].string,
-			 stringtable->strings[i].length);
+				stringtable->strings[i].length);
 	  fprintf (e, "\n");
 	}
     }
@@ -3298,7 +3317,7 @@ write_rc_versioninfo (FILE *e, const rc_versioninfo *versioninfo)
     fprintf (e, " FILESUBTYPE 0x%x\n", (unsigned int) f->file_subtype);
   if (f->file_date_ms != 0 || f->file_date_ls != 0)
     fprintf (e, "/* Date: %u, %u.  */\n",
-    	     (unsigned int) f->file_date_ms, (unsigned int) f->file_date_ls);
+	     (unsigned int) f->file_date_ms, (unsigned int) f->file_date_ls);
 
   fprintf (e, "BEGIN\n");
 
@@ -3366,7 +3385,7 @@ rcdata_copy (const rc_rcdata_item *src, bfd_byte *dst)
   if (! src)
     return 0;
   switch (src->type)
-	{
+    {
     case RCDATA_WORD:
       if (dst)
 	windres_put_16 (&wrtarget, dst, (rc_uint_type) src->u.word);
diff --git a/binutils/resres.c b/binutils/resres.c
index d96fb144a8c..6505580597c 100644
--- a/binutils/resres.c
+++ b/binutils/resres.c
@@ -201,11 +201,11 @@ read_resource_entry (windres_bfd *wrbfd, rc_uint_type *off, rc_uint_type omax)
 
   /* Read additional resource header */
   read_res_data (wrbfd, off, omax, &l, BIN_RES_INFO_SIZE);
-  resinfo.version = windres_get_32 (wrbfd, l.version, 4);
-  resinfo.memflags = windres_get_16 (wrbfd, l.memflags, 2);
-  resinfo.language = windres_get_16 (wrbfd, l.language, 2);
-  /* resinfo.version2 = windres_get_32 (wrbfd, l.version2, 4); */
-  resinfo.characteristics = windres_get_32 (wrbfd, l.characteristics, 4);
+  resinfo.version = windres_get_32 (wrbfd, l.version);
+  resinfo.memflags = windres_get_16 (wrbfd, l.memflags);
+  resinfo.language = windres_get_16 (wrbfd, l.language);
+  /* resinfo.version2 = windres_get_32 (wrbfd, l.version2); */
+  resinfo.characteristics = windres_get_32 (wrbfd, l.characteristics);
 
   off[0] = (off[0] + 3) & ~3;
 
@@ -464,8 +464,8 @@ read_res_data_hdr (windres_bfd *wrbfd, rc_uint_type *off, rc_uint_type omax,
     fatal ("%s: unexpected end of file %ld/%ld", filename,(long) off[0], (long) omax);
 
   get_windres_bfd_content (wrbfd, &brh, off[0], BIN_RES_HDR_SIZE);
-  reshdr->data_size = windres_get_32 (wrbfd, brh.data_size, 4);
-  reshdr->header_size = windres_get_32 (wrbfd, brh.header_size, 4);
+  reshdr->data_size = windres_get_32 (wrbfd, brh.data_size);
+  reshdr->header_size = windres_get_32 (wrbfd, brh.header_size);
   off[0] += BIN_RES_HDR_SIZE;
 }
 
@@ -542,12 +542,12 @@ read_res_id (windres_bfd *wrbfd, rc_uint_type *off, rc_uint_type omax, rc_res_id
   rc_uint_type len;
 
   read_res_data (wrbfd, off, omax, &bid, BIN_RES_ID - 2);
-  ord = (unsigned short) windres_get_16 (wrbfd, bid.sig, 2);
+  ord = (unsigned short) windres_get_16 (wrbfd, bid.sig);
   if (ord == 0xFFFF)		/* an ordinal id */
     {
       read_res_data (wrbfd, off, omax, bid.id, BIN_RES_ID - 2);
       id->named = 0;
-      id->u.id = windres_get_16 (wrbfd, bid.id, 2);
+      id->u.id = windres_get_16 (wrbfd, bid.id);
     }
   else
     /* named id */
@@ -575,7 +575,7 @@ read_unistring (windres_bfd *wrbfd, rc_uint_type *off, rc_uint_type omax,
   do
     {
       read_res_data (wrbfd, &soff, omax, d, sizeof (unichar));
-      c = windres_get_16 (wrbfd, d, 2);
+      c = windres_get_16 (wrbfd, d);
     }
   while (c != 0);
   l = ((soff - off[0]) / sizeof (unichar));
@@ -585,7 +585,7 @@ read_unistring (windres_bfd *wrbfd, rc_uint_type *off, rc_uint_type omax,
   do
     {
       read_res_data (wrbfd, off, omax, d, sizeof (unichar));
-      c = windres_get_16 (wrbfd, d, 2);
+      c = windres_get_16 (wrbfd, d);
       *p++ = c;
     }
   while (c != 0);
diff --git a/binutils/windint.h b/binutils/windint.h
index 3b950acba6c..10cf46ee477 100644
--- a/binutils/windint.h
+++ b/binutils/windint.h
@@ -1087,9 +1087,9 @@ extern void get_windres_bfd_content (windres_bfd *, void *, rc_uint_type, rc_uin
 extern void windres_put_8 (windres_bfd *, void *, rc_uint_type);
 extern void windres_put_16 (windres_bfd *, void *, rc_uint_type);
 extern void windres_put_32 (windres_bfd *, void *, rc_uint_type);
-extern rc_uint_type windres_get_8 (windres_bfd *, const void *, rc_uint_type);
-extern rc_uint_type windres_get_16 (windres_bfd *, const void *, rc_uint_type);
-extern rc_uint_type windres_get_32 (windres_bfd *, const void *, rc_uint_type);
+extern rc_uint_type windres_get_8 (windres_bfd *, const void *);
+extern rc_uint_type windres_get_16 (windres_bfd *, const void *);
+extern rc_uint_type windres_get_32 (windres_bfd *, const void *);
 
 extern void set_windres_bfd (windres_bfd *, bfd *, asection *, rc_uint_type);
 extern void set_windres_bfd_endianness (windres_bfd *, int);
diff --git a/binutils/windres.c b/binutils/windres.c
index b41353b0b88..cfd306bd787 100644
--- a/binutils/windres.c
+++ b/binutils/windres.c
@@ -1210,23 +1210,15 @@ target_put_32 (void *p, rc_uint_type value)
 }
 
 static rc_uint_type
-target_get_8 (const void *p, rc_uint_type length)
+target_get_8 (const void *p)
 {
-  rc_uint_type ret;
-
-  if (length < 1)
-    fatal ("Resource too small for getting 8-bit value.");
-
-  ret = (rc_uint_type) *((const bfd_byte *) p);
+  rc_uint_type ret = *((const bfd_byte *) p);
   return ret & 0xff;
 }
 
 static rc_uint_type
-target_get_16 (const void *p, rc_uint_type length)
+target_get_16 (const void *p)
 {
-  if (length < 2)
-    fatal ("Resource too small for getting 16-bit value.");
-
   if (target_is_bigendian)
     return bfd_getb16 (p);
   else
@@ -1234,11 +1226,8 @@ target_get_16 (const void *p, rc_uint_type length)
 }
 
 static rc_uint_type
-target_get_32 (const void *p, rc_uint_type length)
+target_get_32 (const void *p)
 {
-  if (length < 4)
-    fatal ("Resource too small for getting 32-bit value.");
-
   if (target_is_bigendian)
     return bfd_getb32 (p);
   else
@@ -1304,14 +1293,12 @@ windres_put_32 (windres_bfd *wrbfd, void *data, rc_uint_type value)
 }
 
 rc_uint_type
-windres_get_8 (windres_bfd *wrbfd, const void *data, rc_uint_type length)
+windres_get_8 (windres_bfd *wrbfd, const void *data)
 {
-  if (length < 1)
-    fatal ("windres_get_8: unexpected eob.");
   switch (WR_KIND(wrbfd))
     {
     case WR_KIND_TARGET:
-      return target_get_8 (data, length);
+      return target_get_8 (data);
     case WR_KIND_BFD:
     case WR_KIND_BFD_BIN_B:
     case WR_KIND_BFD_BIN_L:
@@ -1323,14 +1310,12 @@ windres_get_8 (windres_bfd *wrbfd, const void *data, rc_uint_type length)
 }
 
 rc_uint_type
-windres_get_16 (windres_bfd *wrbfd, const void *data, rc_uint_type length)
+windres_get_16 (windres_bfd *wrbfd, const void *data)
 {
-  if (length < 2)
-    fatal ("windres_get_16: unexpected eob.");
   switch (WR_KIND(wrbfd))
     {
     case WR_KIND_TARGET:
-      return target_get_16 (data, length);
+      return target_get_16 (data);
     case WR_KIND_BFD:
     case WR_KIND_BFD_BIN_B:
       return bfd_get_16 (WR_BFD(wrbfd), data);
@@ -1343,14 +1328,12 @@ windres_get_16 (windres_bfd *wrbfd, const void *data, rc_uint_type length)
 }
 
 rc_uint_type
-windres_get_32 (windres_bfd *wrbfd, const void *data, rc_uint_type length)
+windres_get_32 (windres_bfd *wrbfd, const void *data)
 {
-  if (length < 4)
-    fatal ("windres_get_32: unexpected eob.");
   switch (WR_KIND(wrbfd))
     {
     case WR_KIND_TARGET:
-      return target_get_32 (data, length);
+      return target_get_32 (data);
     case WR_KIND_BFD:
     case WR_KIND_BFD_BIN_B:
       return bfd_get_32 (WR_BFD(wrbfd), data);


More information about the Binutils-cvs mailing list