Re: [PATCH] mv: prevent mismatched data when ignoring errors.
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Mar 17, 2014, 19:06 UTC
- Message-ID
- <CAPig+cTs23=j_1OsB4FUUb1PZWubhad+XBCa1iEx4jChZE2x4w@mail.gmail.com>
- In-Reply-To
- <53270FC2.2030701@alum.mit.edu>
On Mon, Mar 17, 2014 at 11:07 AM, Michael Haggerty <mhagger@alum.mit.edu> wrote:
Show 13 quoted lines
> On 03/17/2014 07:33 AM, Junio C Hamano wrote: >> Junio C Hamano <gitster@pobox.com> writes: >> >>> Would it make sense to go one step further to introduce two macros >>> to make this kind of screw-up less likely? > potential callers that I noticed, ALLOC_GROW() was used immediately > before making space in the array for a new element. So I suggest > something more like > > +#define MOVE_DOWN(array, nr, at, count) \ > + memmove((array) + (at) + (count), \ > + (array) + (at), \ > + sizeof((array)[0]) * ((nr) - (at)))
Each time I read these, my brain (for whatever reason) interprets the names UP and DOWN opposite of the intended meaning, which makes them confusing. Perhaps INSERT_GAP and CLOSE_GAP would avoid such problems, and be more consistent with Michael's proposed ALLOC_INSERT_GAP.
Show 17 quoted lines
> +#define ALLOC_INSERT_GAP(array, nr, at, count, alloc) \
> + do { \
> + ALLOC_GROW((array), (nr) + (count), (alloc)); \
> + MOVE_DOWN((array), (nr), (at), (count)); \
> + } while (0)
>
> Also, count==1 is so frequent that this special case might deserve its
> own macro pair.
>
> I'm not inspired by these macro names, though.
>
> Michael
>
> --
> Michael Haggerty
> mhagger@alum.mit.edu
> http://softwareswirl.blogspot.com/