ccan.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Damien Grassart <damien@grassart.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: ccan@lists.ozlabs.org
Subject: Re: [PATCH 1/2] darray: Fix bug in the darray_remove() macro
Date: Sun, 27 Aug 2017 23:02:11 +0200	[thread overview]
Message-ID: <CADZuF1mhrMb+t+RX1BWgAszYNZphn5u-9UjJehS-th5TuQeQtA@mail.gmail.com> (raw)
In-Reply-To: <20170827025642.GN2772@umbus.fritz.box>


[-- Attachment #1.1: Type: text/plain, Size: 1727 bytes --]

Good point about shadowing index(3), I'll send a patch renaming all the
uses of 'index'.

On Sun, Aug 27, 2017 at 4:56 AM, David Gibson <david@gibson.dropbear.id.au>
wrote:

> 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@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
>

[-- Attachment #1.2: Type: text/html, Size: 2640 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
ccan mailing list
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan

  reply	other threads:[~2017-08-27 21:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-26 16:26 [PATCH 1/2] darray: Fix bug in the darray_remove() macro Damien Grassart
2017-08-27  2:56 ` David Gibson
2017-08-27 21:02   ` Damien Grassart [this message]
2017-08-27 21:26   ` [PATCH 1/2] darray: Rename identifiers starting with an underscore Damien Grassart
2017-08-27 21:26     ` [PATCH 2/2] darray: Fix bug in the darray_remove() macro Damien Grassart
2017-08-28  2:48       ` David Gibson
2017-08-28  5:03         ` Damien Grassart
2017-08-28  5:09         ` [PATCH] " Damien Grassart
2017-08-29  4:54           ` David Gibson
2017-08-29 10:08             ` Damien Grassart
2017-08-28  2:43     ` [PATCH 1/2] darray: Rename identifiers starting with an underscore David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADZuF1mhrMb+t+RX1BWgAszYNZphn5u-9UjJehS-th5TuQeQtA@mail.gmail.com \
    --to=damien@grassart.com \
    --cc=ccan@lists.ozlabs.org \
    --cc=david@gibson.dropbear.id.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).