Re: [PATCH 1/5] parseopt: fix :(optional) at command line to only ignore missing files
- From
D. Ben Knoble <ben.knoble+github@gmail.com>
- Date
- Nov 4, 2025, 18:24 UTC
- Message-ID
- <CALnO6CBgTu4Qtr8xwPCerrpqfAf02SV-bONLOUgq0X70eDThfw@mail.gmail.com>
- In-Reply-To
- <xmqqwm45puqr.fsf@gitster.g>
On Tue, Nov 4, 2025 at 12:34 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 52 quoted lines
>
> Junio C Hamano <gitster@pobox.com> writes:
>
> > Phillip Wood <phillip.wood123@gmail.com> writes:
> >
> >> Hi Ben
> >>
> >> These all look good to me though I agree with Junio's comments on patch
> >> 3. It would be nice to get at least the fist patch merged in time for
> >> 2.52.0.
> >
> > Yup, let me do exactly that ;-)
> >
> > Thanks, both.
>
> Let me have this on top of Ben's 5-patch series.
>
> ----- >8 -----
> Subject: [PATCH] parseopt: remove unreachable code
>
> At this point in the code after running skip_prefix() on the
> variable and receiving the result in the same variable, the contents
> of the variable can never be NULL. The function either (1) updates
> the variable to point at a later part of the string it originally
> pointed at, or (2) leaves it intact if the string does not have the
> prefix. (1) will never make the variable NULL, and (2) cannot be
> the source of NULL, because the variable cannot be NULL before
> calling skip_prefix(), which would die immediately by dereferencing
> the NULL pointer in that case.
>
> Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
> parse-options.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/parse-options.c b/parse-options.c
> index 27c1e75d53..97a55300e8 100644
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -223,8 +223,6 @@ static enum parse_opt_result do_get_value(struct parse_opt_ctx_t *p,
> return 0;
>
> is_optional = skip_prefix(value, ":(optional)", &value);
> - if (!value)
> - is_optional = false;
> value = fix_filename(p->prefix, value);
> if (is_optional && is_missing_file(value)) {
> free((char *)value);
> --
> 2.52.0-rc0-28-g4cf919bd7b
>Ah, that's fine, and I won't send a new version unless we need it. Thanks!
I do wonder about Phillip's comment: perhaps it should have been `!*value`? But then something else has to be fixed because value is no longer ":(optional)" which maybe was intended as a literal filename? IDK.