public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [committed/vms] Fix thinko that can corrupt archives
@ 2010-11-04 16:17 Tristan Gingold
  0 siblings, 0 replies; only message in thread
From: Tristan Gingold @ 2010-11-04 16:17 UTC (permalink / raw)
  To: Binutils

Hi,

this patch fix a stupid thinko that could generate garbage: some index block were freed in the reverse order.
Also, these blocks are cleared when allocated to make the output deterministic.

Committed on trunk.

Tristan.

bfd/
2010-11-04  Tristan Gingold  <gingold@adacore.com>

	* vms-lib.c (vms_write_index): Fix thinko: reverse the loop.
	Use bfd_zmalloc instead of bfd_malloc.  Fix comment.

Index: bfd/vms-lib.c
===================================================================
RCS file: /cvs/src/src/bfd/vms-lib.c,v
retrieving revision 1.13
diff -c -r1.13 vms-lib.c
*** bfd/vms-lib.c	4 Nov 2010 13:51:37 -0000	1.13
--- bfd/vms-lib.c	4 Nov 2010 16:13:56 -0000
***************
*** 1591,1597 ****
    /* Allocate first index block.  */
    level = 1;
    if (abfd != NULL)
!     rblk[0] = bfd_malloc (sizeof (struct vms_indexdef));
    blk[0].vbn = (*vbn)++;
    blk[0].len = 0;
    blk[0].lastlen = 0;
--- 1591,1597 ----
    /* Allocate first index block.  */
    level = 1;
    if (abfd != NULL)
!     rblk[0] = bfd_zmalloc (sizeof (struct vms_indexdef));
    blk[0].vbn = (*vbn)++;
    blk[0].len = 0;
    blk[0].lastlen = 0;
***************
*** 1698,1704 ****
                    /* Need to create a parent.  */
                    if (abfd != NULL)
                      {
!                       rblk[level] = bfd_malloc (sizeof (struct vms_indexdef));
                        bfd_putl32 (*vbn, rblk[j]->parent);
                      }
                    blk[level].vbn = (*vbn)++;
--- 1698,1704 ----
                    /* Need to create a parent.  */
                    if (abfd != NULL)
                      {
!                       rblk[level] = bfd_zmalloc (sizeof (struct vms_indexdef));
                        bfd_putl32 (*vbn, rblk[j]->parent);
                      }
                    blk[level].vbn = (*vbn)++;
***************
*** 1717,1723 ****
                    memcpy (rblk[j + 1]->keys + blk[j + 1].len,
                            rblk[j]->keys + blk[j].len,
                            blk[j].lastlen);
!                   /* Fix the entry (which in always the first field of an entry.  */
                    rfa = (struct vms_rfa *)(rblk[j + 1]->keys + blk[j + 1].len);
                    bfd_putl32 (blk[j].vbn, rfa->vbn);
                    bfd_putl16 (RFADEF__C_INDEX, rfa->offset);
--- 1717,1724 ----
                    memcpy (rblk[j + 1]->keys + blk[j + 1].len,
                            rblk[j]->keys + blk[j].len,
                            blk[j].lastlen);
!                   /* Fix the entry (which in always the first field of an
! 		     entry.  */
                    rfa = (struct vms_rfa *)(rblk[j + 1]->keys + blk[j + 1].len);
                    bfd_putl32 (blk[j].vbn, rfa->vbn);
                    bfd_putl16 (RFADEF__C_INDEX, rfa->offset);
***************
*** 1806,1812 ****
      return TRUE;
  
    /* Flush.  */
!   for (j = 0; j < level; j++)
      {
        if (j > 0)
          {
--- 1807,1813 ----
      return TRUE;
  
    /* Flush.  */
!   for (j = level - 1; j >= 0; j--)
      {
        if (j > 0)
          {

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

only message in thread, other threads:[~2010-11-04 16:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-04 16:17 [committed/vms] Fix thinko that can corrupt archives Tristan Gingold

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