[PATCH 2/2] xfsdump: don't do pointer math twice
Eric Sandeen
sandeen at sandeen.net
Fri Aug 21 12:24:54 CDT 2015
On 8/21/15 9:01 AM, rjohnston at sgi.com wrote:
> The pointer math when calculating the address for the call to memset
> is incorrect, so we are clearing the wrong memory location.
>
> i2gmap is of type i2gseg_t
>
> oldsize has already computed the pointer offset
> oldsize = inomap.hnkmaplen * SEGPERHNK * sizeof(i2gseg_t);
> the memset call is using
> inomap.i2gmap + oldsize == &inomap.i2gmap[oldsize]
> so we were doing the pointer math twice.
>
> We already compensate for the length of each item in oldsize so
> adding need to add a (char *) cast to the memset parameter.
What about just doing:
memset(&inomap.i2gmap[numsegs - SEGPERHNK], 0,
SEGPERHNK * sizeof(i2gseg_t));
which more clearly shows that we're setting the new array members
to zero.
(could do oldsegs = inomap.hnkmaplen * SEGPERHNK; prior to the
hnkmaplen++, if that makes it any more readable...)
*shrug* it seems a little clearer to me, anyway.
Thanks,
-Eric
> ---
> dump/inomap.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> Index: b/dump/inomap.c
> ===================================================================
> --- a/dump/inomap.c
> +++ b/dump/inomap.c
> @@ -1143,7 +1143,7 @@ cb_add_inogrp( void *arg1, intgen_t fsfd
> return -1;
>
> /* zero the new portion of the i2gmap */
> - memset(inomap.i2gmap + oldsize,
> + memset((char *)inomap.i2gmap + oldsize,
> 0,
> SEGPERHNK * sizeof(i2gseg_t));
> }
>
> _______________________________________________
> xfs mailing list
> xfs at oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
>
More information about the xfs
mailing list