Re: [PATCH 2/3] getpwuid(mingw): provide a better default for the user name
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Oct 16, 2018, 13:06 UTC
- Message-ID
- <nycvar.QRO.7.76.6.1810161506230.4546@tvgsbejvaqbjf.bet>
- In-Reply-To
- <CAPig+cTvKicLKZO38AcVzXJJhZ1CajOhiADotRJ0V7EJXBicUA@mail.gmail.com>
Hi Eric,
On Tue, 16 Oct 2018, Eric Sunshine wrote:
Show 15 quoted lines
> On Tue, Oct 16, 2018 at 8:38 AM Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
> > On Mon, 15 Oct 2018, Eric Sunshine wrote:
> > > On Mon, Oct 15, 2018 at 5:47 AM Johannes Schindelin via GitGitGadget
> > > <gitgitgadget@gmail.com> wrote:
> > > > + len = ARRAY_SIZE(wbuffer);
> > > > + if (GetUserNameExW(type, wbuffer, &len)) {
> > > > + char *converted = xmalloc((len *= 3));
> >
> > Oh wow. I *just* realized this. It is an off-by-one: the `xmalloc()` call
> > needs to receive `len + 1` to accommodate for the trailing NUL. Will fix,
> > too.
>
> Or, xmallocz() (note the "z") which gives you overflow-checking of the
> +1 for free.Very good point! Thanks for the suggestion, Dscho