[ccan] [PATCH 1/2] darray: Fix bug in the darray_remove() macro
David Gibson
david at gibson.dropbear.id.au
Sun Aug 27 12:56:42 AEST 2017
On Sat, Aug 26, 2017 at 06:26:20PM +0200, Damien Grassart wrote:
> The memmove() call should be using the index argument to determine the
> number of bytes to copy.
>
> Signed-off-by: Damien Grassart <damien at grassart.com>
No question that was a bug. Fix applied.
Note for a possible future cleanup: calling identifiers 'index' is
usually a bad idea, because it shadows index(3) in the C library,
which means you can get really confusing errors (or lack of errors) if
you remove the declaration but not the users.
> ---
> ccan/darray/darray.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/ccan/darray/darray.h b/ccan/darray/darray.h
> index 75112419..8d47645b 100644
> --- a/ccan/darray/darray.h
> +++ b/ccan/darray/darray.h
> @@ -225,7 +225,7 @@ typedef darray(unsigned long) darray_ulong;
> /* Warning, slow: Requires copying all elements after removed item. */
> #define darray_remove(arr, index) do { \
> if (index < arr.size-1) \
> - memmove(&(arr).item[index], &(arr).item[index+1], ((arr).size-1-i)*sizeof(*(arr).item)); \
> + memmove(&(arr).item[index], &(arr).item[index+1], ((arr).size-1-index)*sizeof(*(arr).item)); \
> (arr).size--; \
> } while(0)
>
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/ccan/attachments/20170827/a2484cb6/attachment.sig>
More information about the ccan
mailing list