--- binutils-2.16.1/bfd/archive.c 3 Mar 2005 11:40:56 -0000 1.34 +++ binutils-2.16.1/bfd/archive.c 8 Jul 2005 06:28:30 -0000 @@ -1308,6 +1308,13 @@ #define getgid() 0 #endif +static void print_ar_size( struct ar_hdr* hdr, int val ) +{ + char buffer[sizeof(hdr->ar_size)+1]; + sprintf(buffer,"%-10d", val); + memcpy(hdr->ar_size,buffer,sizeof(hdr->ar_size)); +} + /* Takes a filename, returns an arelt_data for it, or NULL if it can't make one. The filename must refer to a filename in the filesystem. The filename field of the ar_hdr will NOT be initialized. If member @@ -1368,7 +1375,7 @@ #endif sprintf ((hdr->ar_gid), "%ld", (long) status.st_gid); sprintf ((hdr->ar_mode), "%-8o", (unsigned int) status.st_mode); - sprintf ((hdr->ar_size), "%-10ld", (long) status.st_size); + print_ar_size(hdr, (long) status.st_size); /* Correct for a lossage in sprintf whereby it null-terminates. I cannot understand how these C losers could design such a ramshackle bunch of IO operations. */ @@ -1660,7 +1667,7 @@ memset (&hdr, 0, sizeof (struct ar_hdr)); strcpy (hdr.ar_name, ename); /* Round size up to even number in archive header. */ - sprintf (&(hdr.ar_size[0]), "%-10d", + print_ar_size(&hdr, (int) ((elength + 1) & ~(bfd_size_type) 1)); strncpy (hdr.ar_fmag, ARFMAG, 2); for (i = 0; i < sizeof (struct ar_hdr); i++) @@ -1913,7 +1920,7 @@ sprintf (hdr.ar_date, "%ld", bfd_ardata (arch)->armap_timestamp); sprintf (hdr.ar_uid, "%ld", (long) getuid ()); sprintf (hdr.ar_gid, "%ld", (long) getgid ()); - sprintf (hdr.ar_size, "%-10d", (int) mapsize); + print_ar_size(&hdr, (int) mapsize); strncpy (hdr.ar_fmag, ARFMAG, 2); for (i = 0; i < sizeof (struct ar_hdr); i++) if (((char *) (&hdr))[i] == '\0') @@ -2068,7 +2075,7 @@ memset (&hdr, 0, sizeof (struct ar_hdr)); hdr.ar_name[0] = '/'; - sprintf (hdr.ar_size, "%-10d", (int) mapsize); + print_ar_size (&hdr, (int) mapsize); sprintf (hdr.ar_date, "%ld", (long) time (NULL)); /* This, at least, is what Intel coff sets the values to. */ sprintf ((hdr.ar_uid), "%d", 0);