Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Sep 2019 07:30:11 -0600
From:      Warner Losh <imp@bsdimp.com>
To:        Sebastian Huber <sebastian.huber@embedded-brains.de>
Cc:        "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org>
Subject:   Re: [PATCH] nvmecontrol: Fix shortopts allocation
Message-ID:  <CANCZdfo_L9AuEqV0ur0xT71vxUX3d8UGhW9kz6mo5AXkP=FJ6w@mail.gmail.com>
In-Reply-To: <20190911082833.32388-1-sebastian.huber@embedded-brains.de>
References:  <20190911082833.32388-1-sebastian.huber@embedded-brains.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Sep 11, 2019 at 2:28 AM Sebastian Huber <
sebastian.huber@embedded-brains.de> wrote:

> Account for potential ':' in the short options string.
> ---
>  sbin/nvmecontrol/comnd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> 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)
>         lopts = malloc((n + 2) * sizeof(struct option));
>         if (lopts == NULL)
>                 err(1, "option memory");
> -       p = shortopts = malloc((n + 3) * sizeof(char));
> +       p = shortopts = malloc((2 * n + 2) * sizeof(char));
>

I'll apply, but I still think this needs to be + 3 to account for the NUL
at the end (even though we kinda know that the 2 options we're adding don't
have :.


>         if (shortopts == NULL)
>                 err(1, "shortopts memory");
>         idx = 0;
> --
> 2.16.4
>
> _______________________________________________
> freebsd-hackers@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfo_L9AuEqV0ur0xT71vxUX3d8UGhW9kz6mo5AXkP=FJ6w>