Re: [PATCH 1/2] add MOVE_ARRAY
- From
Jeff King <peff@peff.net>
- Date
- Jul 16, 2017, 10:31 UTC
- Message-ID
- <20170716103132.z36audbi7wxot7e6@sigill.intra.peff.net>
- In-Reply-To
- <ec78a849-36e4-4b1d-1ad6-46dcc39a1396@web.de>
On Sat, Jul 15, 2017 at 09:36:20PM +0200, René Scharfe wrote:
Show 8 quoted lines
> Similar to COPY_ARRAY (introduced in 60566cbb58), add a safe and > convenient helper for moving potentially overlapping ranges of array > entries. It infers the element size, multiplies automatically and > safely to get the size in bytes, does a basic type safety check by > comparing element sizes and unlike memmove(3) it supports NULL > pointers iff 0 elements are to be moved. > > Also add a semantic patch to demonstrate the helper's intended usage.
If we have COPY_ARRAY(), I think it's foolish not to provide the matching MOVE_ARRAY(). If it were just the "if (n)", I might say we could just do this inline in the few calls that care. But I really like the size safety.
I agree with your comments elsewhere that we don't need to worry about the case where one of the arrays is NULL but the size is not zero. That's a flat-out bug.
-Peff