Re: [PATCH 05/18] convert trivial cases to ALLOC_ARRAY
- From
Jeff King <peff@peff.net>
- Date
- Feb 16, 2016, 04:23 UTC
- Message-ID
- <20160216042346.GB27060@sigill.intra.peff.net>
- In-Reply-To
- <CAPig+cRTz4Fb10JDWLjmTEXzQ+FbvmKU51A9B3vmwBepDX+BYA@mail.gmail.com>
On Mon, Feb 15, 2016 at 11:22:12PM -0500, Eric Sunshine wrote:
Show 26 quoted lines
> On Mon, Feb 15, 2016 at 4:51 PM, Jeff King <peff@peff.net> wrote: > > Each of these cases can be converted to use ALLOC_ARRAY or > > REALLOC_ARRAY, which has two advantages: > > > > 1. It automatically checks the array-size multiplication > > for overflow. > > > > 2. It always uses sizeof(*array) for the element-size, > > so that it can never go out of sync with the declared > > type of the array. > > > > Signed-off-by: Jeff King <peff@peff.net> > > --- > > diff --git a/compat/mingw.c b/compat/mingw.c > > index 77a51d3..0eabe68 100644 > > --- a/compat/mingw.c > > +++ b/compat/mingw.c > > @@ -854,7 +854,7 @@ static char **get_path_split(void) > > if (!n) > > return NULL; > > > > - path = xmalloc((n+1)*sizeof(char *)); > > + ALLOC_ARRAY(path, n+1); > > Elsewhere in this patch, you've reformatted "x+c" as "x + c"; perhaps > do so here, as well.
Will do. I noticed while going over this before sending it out that it may also be technically possible for "n+1" to overflow here (and I think in a few other places in this patch). I don't know how paranoid we want to be.
-Peff