Date: Fri, 13 Sep 2019 07:53:43 +0200 From: Sebastian Huber <sebastian.huber@embedded-brains.de> To: Warner Losh <imp@bsdimp.com> Cc: "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org> Subject: Re: [PATCH] nvmecontrol: Fix shortopts allocation Message-ID: <ad23539b-92f1-445d-0d79-30fbfa2fb0c8@embedded-brains.de> In-Reply-To: <CANCZdfo_L9AuEqV0ur0xT71vxUX3d8UGhW9kz6mo5AXkP=FJ6w@mail.gmail.com> References: <20190911082833.32388-1-sebastian.huber@embedded-brains.de> <CANCZdfo_L9AuEqV0ur0xT71vxUX3d8UGhW9kz6mo5AXkP=FJ6w@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 11/09/2019 15:30, Warner Losh wrote: >=20 >=20 > On Wed, Sep 11, 2019 at 2:28 AM Sebastian Huber=20 > <sebastian.huber@embedded-brains.de=20 > <mailto:sebastian.huber@embedded-brains.de>> wrote: >=20 > Account for potential ':' in the short options string. > --- > =C2=A0sbin/nvmecontrol/comnd.c | 2 +- > =C2=A01 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/sbin/nvmecontrol/comnd.c b/sbin/nvmecontrol/comnd.c > index d8d97ad11b5..a91969ff766 100644 > --- a/sbin/nvmecontrol/comnd.c > +++ b/sbin/nvmecontrol/comnd.c > @@ -189,7 +189,7 @@ arg_parse(int argc, char * const * argv, const > struct cmd *f) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 lopts =3D malloc((n + 2) * sizeof(stru= ct option)); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (lopts =3D=3D NULL) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 err(1, "op= tion memory"); > -=C2=A0 =C2=A0 =C2=A0 =C2=A0p =3D shortopts =3D malloc((n + 3) * si= zeof(char)); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0p =3D shortopts =3D malloc((2 * n + 2) = * sizeof(char)); >=20 >=20 > I'll apply, but I still think this needs to be=C2=A0+ 3 to account for = the=20 > NUL at the end (even though we kinda know that the 2 options we're=20 > adding don't have :. Thanks for checking it in. I wondered why there was a + 3, we have in=20 arg_parse() with unrelated code omitted: p =3D shortopts =3D malloc((2 * n + 3) * sizeof(char)); for (i =3D 0; i < n; i++) { if (isprint(opts[i].short_arg)) { *p++ =3D opts[i].short_arg; if (lopts[i].has_arg) *p++ =3D ':'; } } *p++ =3D '?'; *p++ =3D '\0'; while ((ch =3D getopt_long(argc, argv, shortopts, lopts, &idx)) !=3D -1) = { Looks like the last ++ is superfluous. --=20 Sebastian Huber, embedded brains GmbH Address : Dornierstr. 4, D-82178 Puchheim, Germany Phone : +49 89 189 47 41-16 Fax : +49 89 189 47 41-09 E-Mail : sebastian.huber@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine gesch=C3=A4ftliche Mitteilung im Sinne des EHUG= .
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ad23539b-92f1-445d-0d79-30fbfa2fb0c8>