public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PATCH: fewer magic numbers in binutils/resbin.c
@ 2006-03-29 12:49 Ben Elliston
  0 siblings, 0 replies; only message in thread
From: Ben Elliston @ 2006-03-29 12:49 UTC (permalink / raw)
  To: binutils

I'm committing the following patch as obvious.  The patch eliminates a
lot of duplicated constants.

Ben

2006-03-29  Ben Elliston  <bje@au.ibm.com>

        * resbin.c: Avoid duplicating constants in calls to reswr_alloc.

Index: resbin.c
===================================================================
RCS file: /cvs/src/src/binutils/resbin.c,v
retrieving revision 1.9
diff -u -p -r1.9 resbin.c
--- resbin.c	10 Oct 2005 15:54:42 -0000	1.9
+++ resbin.c	29 Mar 2006 00:21:03 -0000
@@ -1331,7 +1331,7 @@ resid_to_bin (struct res_id id, int big_
   if (! id.named)
     {
       d->length = 4;
-      d->data = (unsigned char *) reswr_alloc (4);
+      d->data = (unsigned char *) reswr_alloc (d->length);
       put_16 (big_endian, 0xffff, d->data);
       put_16 (big_endian, id.u.id, d->data + 2);
     }
@@ -1408,7 +1408,7 @@ res_to_bin_accelerator (const struct acc
 
       d = (struct bindata *) reswr_alloc (sizeof *d);
       d->length = 8;
-      d->data = (unsigned char *) reswr_alloc (8);
+      d->data = (unsigned char *) reswr_alloc (d->length);
 
       put_16 (big_endian,
 	      a->flags | (a->next != NULL ? 0 : ACC_LAST),
@@ -1434,7 +1434,7 @@ res_to_bin_cursor (const struct cursor *
 
   d = (struct bindata *) reswr_alloc (sizeof *d);
   d->length = 4;
-  d->data = (unsigned char *) reswr_alloc (4);
+  d->data = (unsigned char *) reswr_alloc (d->length);
 
   put_16 (big_endian, c->xhotspot, d->data);
   put_16 (big_endian, c->yhotspot, d->data + 2);
@@ -1459,7 +1459,7 @@ res_to_bin_group_cursor (const struct gr
 
   first = (struct bindata *) reswr_alloc (sizeof *first);
   first->length = 6;
-  first->data = (unsigned char *) reswr_alloc (6);
+  first->data = (unsigned char *) reswr_alloc (first->length);
 
   put_16 (big_endian, 0, first->data);
   put_16 (big_endian, 2, first->data + 2);
@@ -1476,7 +1476,7 @@ res_to_bin_group_cursor (const struct gr
 
       d = (struct bindata *) reswr_alloc (sizeof *d);
       d->length = 14;
-      d->data = (unsigned char *) reswr_alloc (14);
+      d->data = (unsigned char *) reswr_alloc (d->length);
 
       put_16 (big_endian, gc->width, d->data);
       put_16 (big_endian, gc->height, d->data + 2);
@@ -1642,7 +1642,7 @@ res_to_bin_dialog (const struct dialog *
 
       d = (struct bindata *) reswr_alloc (sizeof *d);
       d->length = 2;
-      d->data = (unsigned char *) reswr_alloc (2);
+      d->data = (unsigned char *) reswr_alloc (d->length);
 
       length += 2;
 
@@ -1687,7 +1687,7 @@ res_to_bin_fontdir (const struct fontdir
 
   first = (struct bindata *) reswr_alloc (sizeof *first);
   first->length = 2;
-  first->data = (unsigned char *) reswr_alloc (2);
+  first->data = (unsigned char *) reswr_alloc (first->length);
 
   first->next = NULL;
   pp = &first->next;
@@ -1701,7 +1701,7 @@ res_to_bin_fontdir (const struct fontdir
 
       d = (struct bindata *) reswr_alloc (sizeof *d);
       d->length = 2;
-      d->data = (unsigned char *) reswr_alloc (2);
+      d->data = (unsigned char *) reswr_alloc (d->length);
 
       put_16 (big_endian, fd->index, d->data);
 
@@ -1733,7 +1733,7 @@ res_to_bin_group_icon (const struct grou
 
   first = (struct bindata *) reswr_alloc (sizeof *first);
   first->length = 6;
-  first->data = (unsigned char *) reswr_alloc (6);
+  first->data = (unsigned char *) reswr_alloc (first->length);
 
   put_16 (big_endian, 0, first->data);
   put_16 (big_endian, 1, first->data + 2);
@@ -1750,7 +1750,7 @@ res_to_bin_group_icon (const struct grou
 
       d = (struct bindata *) reswr_alloc (sizeof *d);
       d->length = 14;
-      d->data = (unsigned char *) reswr_alloc (14);
+      d->data = (unsigned char *) reswr_alloc (d->length);
 
       d->data[0] = gi->width;
       d->data[1] = gi->height;
@@ -1875,7 +1875,7 @@ res_to_bin_menuexitems (const struct men
 
       d = (struct bindata *) reswr_alloc (sizeof *d);
       d->length = 12;
-      d->data = (unsigned char *) reswr_alloc (12);
+      d->data = (unsigned char *) reswr_alloc (d->length);
 
       length += 12;
 
@@ -1903,7 +1903,7 @@ res_to_bin_menuexitems (const struct men
 
 	  d = (struct bindata *) reswr_alloc (sizeof *d);
 	  d->length = 4;
-	  d->data = (unsigned char *) reswr_alloc (4);
+	  d->data = (unsigned char *) reswr_alloc (d->length);
 
 	  put_32 (big_endian, mi->help, d->data);
 
@@ -1948,13 +1948,13 @@ res_to_bin_rcdata (const struct rcdata_i
 
 	case RCDATA_WORD:
 	  d->length = 2;
-	  d->data = (unsigned char *) reswr_alloc (2);
+	  d->data = (unsigned char *) reswr_alloc (d->length);
 	  put_16 (big_endian, ri->u.word, d->data);
 	  break;
 
 	case RCDATA_DWORD:
 	  d->length = 4;
-	  d->data = (unsigned char *) reswr_alloc (4);
+	  d->data = (unsigned char *) reswr_alloc (d->length);
 	  put_32 (big_endian, ri->u.dword, d->data);
 	  break;
 
@@ -2060,7 +2060,7 @@ res_to_bin_versioninfo (const struct ver
 
   first = (struct bindata *) reswr_alloc (sizeof *first);
   first->length = 6;
-  first->data = (unsigned char *) reswr_alloc (6);
+  first->data = (unsigned char *) reswr_alloc (first->length);
 
   length = 6;
 
@@ -2086,7 +2086,7 @@ res_to_bin_versioninfo (const struct ver
 
       d = (struct bindata *) reswr_alloc (sizeof *d);
       d->length = 52;
-      d->data = (unsigned char *) reswr_alloc (52);
+      d->data = (unsigned char *) reswr_alloc (d->length);
 
       length += 52;
 
@@ -2120,7 +2120,7 @@ res_to_bin_versioninfo (const struct ver
 
       vid = (struct bindata *) reswr_alloc (sizeof *vid);
       vid->length = 6;
-      vid->data = (unsigned char *) reswr_alloc (6);
+      vid->data = (unsigned char *) reswr_alloc (vid->length);
 
       length += 6;
       vilen = 6;
@@ -2153,7 +2153,7 @@ res_to_bin_versioninfo (const struct ver
 
 	    vsd = (struct bindata *) reswr_alloc (sizeof *vsd);
 	    vsd->length = 6;
-	    vsd->data = (unsigned char *) reswr_alloc (6);
+	    vsd->data = (unsigned char *) reswr_alloc (vsd->length);
 
 	    length += 6;
 	    vilen += 6;
@@ -2183,7 +2183,7 @@ res_to_bin_versioninfo (const struct ver
 
 		vssd = (struct bindata *) reswr_alloc (sizeof *vssd);
 		vssd->length = 6;
-		vssd->data = (unsigned char *) reswr_alloc (6);
+		vssd->data = (unsigned char *) reswr_alloc (vssd->length);
 
 		length += 6;
 		vilen += 6;
@@ -2241,7 +2241,7 @@ res_to_bin_versioninfo (const struct ver
 
 	    vvd = (struct bindata *) reswr_alloc (sizeof *vvd);
 	    vvd->length = 6;
-	    vvd->data = (unsigned char *) reswr_alloc (6);
+	    vvd->data = (unsigned char *) reswr_alloc (vvd->length);
 
 	    length += 6;
 	    vilen += 6;
@@ -2271,7 +2271,7 @@ res_to_bin_versioninfo (const struct ver
 
 		vvsd = (struct bindata *) reswr_alloc (sizeof *vvsd);
 		vvsd->length = 4;
-		vvsd->data = (unsigned char *) reswr_alloc (4);
+		vvsd->data = (unsigned char *) reswr_alloc (vvsd->length);
 
 		length += 4;
 		vilen += 4;

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

only message in thread, other threads:[~2006-03-29  0:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-29 12:49 PATCH: fewer magic numbers in binutils/resbin.c Ben Elliston

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