HomeFreeBSD

Fix gcc array subscript above bounds warning

Description

Fix gcc array subscript above bounds warning

In a debug build, certain GCC versions flag an array bounds warning in
the below code from dnode_sync.c

} else {
        int i;
        ASSERT(dn->dn_next_nblkptr[txgoff] < dnp->dn_nblkptr);
        /* the blkptrs we are losing better be unallocated */
        for (i = dn->dn_next_nblkptr[txgoff];
            i < dnp->dn_nblkptr; i++)
                ASSERT(BP_IS_HOLE(&dnp->dn_blkptr[i]));

This usage is in fact safe, since the ASSERT ensures the index does
not exceed to maximum possible number of block pointers. However gcc
can't determine that the assignment 'i = dn->dn_next_nblkptr[txgoff];'
falls within the array bounds so it issues a warning. To avoid this,
initialize i to zero to make gcc happy but skip the elements before
dn->dn_next_nblkptr[txgoff] in the loop body. Since a dnode contains
at most 3 block pointers this overhead should be negligible.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #950

Details

Provenance
Ned Bass <bass6@llnl.gov>Authored on Dec 26 2012, 10:56 PM
Brian Behlendorf <behlendorf1@llnl.gov>Committed on Jan 7 2013, 7:21 PM
Parents
rGe44056fcb644: Merge branch 'io_schedule'
Branches
Unknown
Tags
Unknown

Event Timeline

Brian Behlendorf <behlendorf1@llnl.gov> committed rG37f000c5aa76: Fix gcc array subscript above bounds warning (authored by Ned Bass <bass6@llnl.gov>).Jan 7 2013, 7:21 PM