From: "Kristoffer Haugsbakk" <kristofferhaugsbakk@fastmail.com>
To: "Junio C Hamano" <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 4/4] format-rev: learn --abbrev, --color, and --date
Date: Mon, 17 Aug 2026 16:48:54 +0200 [thread overview]
Message-ID: <0bd9c642-9e88-4c82-81ee-20fdeb3c2797@app.fastmail.com> (raw)
In-Reply-To: <xmqqbjb4ktz5.fsf@gitster.g>
On Sat, Aug 15, 2026, at 04:17, Junio C Hamano wrote:
> kristofferhaugsbakk@fastmail.com writes:
>
>> +static int date_cb(const struct option *option,
>> + const char *arg,
>> + int unset)
>> +{
>> + struct rev_info *data = option->value;
>> + parse_date_format(arg, &data->date_mode);
>> + data->date_mode_explicit = 1;
>> + BUG_ON_OPT_NEG(unset);
>> + return 0;
>> +}
>
> This BUG_ON_OPT_NEG(unset) is a bit curious and confusing to me. If
> the caller could pass unset==1 (e.g., "--no-date"), option->value
> would be NULL, and we would already have dereferenced data->date_mode
> when preparing to call parse_date_format().
Well spotted.
>
> On the other hand, ...
>
>> + OPT_CALLBACK_F(0, "date", &data.rev, N_("date"),
>> + N_("date format"),
>> + PARSE_OPT_NONEG, date_cb),
>
> ... because we mark the option entry with PARSE_OPT_NONEG,
> "--no-date" would not cause date_cb() to be called with unset==1.
>
> I guess, from existing uses of BUG_ON_OPT_NEG() elsewhere (like
> apply.c), that the intention is to notice when this callback
> function is broken by future changes, i.e., somebody careless makes
> the calling parse_options(), or an additional side caller that calls
> this callback directly, pass unset==1 and option->value==NULL
> combinations. But then the assertion should come before the first
> potentially problematic use, i.e., in this order:
This is totally a monkey see and moneky do situation. Mirroring
parse-options flags as `BUG` statements. Down to the outright wrong
assertion/BUG placement. So this needs to be changed
I have these same statements on the existing callback, for `--null`:
static int format_nul_cb(const struct option *option,
const char *arg,
int unset)
{
struct format_rev_data *data = option->value;
data->nul_input = 1;
data->nul_output = 1;
BUG_ON_OPT_NEG(unset);
BUG_ON_OPT_ARG(arg);
return 0;
}
But this does not have the `NULL` deref. problem since we just
unconditionally set two boolean values. Still, for readability it’s
better for these two statements to go at the start. Since they are
preconditions. I will add this as a patch/commit to the series.
>
> struct rev_info *data = option->value;
>
> BUG_ON_OPT_NEG(unset);
> parse_date_format(arg, &data->date_mode);
> data->date_mode_explicit = 1;
> return 0;
>
> or the assertion will not trigger before the code segfaults, no?
next prev parent reply other threads:[~2026-08-17 14:49 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 17:23 [PATCH 0/4] format-rev: add --abbrev, --color, and --date kristofferhaugsbakk
2026-08-13 17:23 ` [PATCH 1/4] format-rev: use lower case for opts description kristofferhaugsbakk
2026-08-13 17:23 ` [PATCH 2/4] format-rev: factor option variables into a struct kristofferhaugsbakk
2026-08-13 18:21 ` Junio C Hamano
2026-08-14 10:54 ` Kristoffer Haugsbakk
2026-08-13 17:23 ` [PATCH 3/4] doc: rev-list-options.adoc: factor out --date alts kristofferhaugsbakk
2026-08-13 17:24 ` [PATCH 4/4] format-rev: learn --abbrev, --color, and --date kristofferhaugsbakk
2026-08-15 2:17 ` Junio C Hamano
2026-08-17 14:48 ` Kristoffer Haugsbakk [this message]
2026-08-17 16:54 ` Junio C Hamano
2026-08-18 5:11 ` Kristoffer Haugsbakk
2026-08-18 9:57 ` [PATCH v2 0/5] format-rev: add " kristofferhaugsbakk
2026-08-18 9:57 ` [PATCH v2 1/5] format-rev: use lower case for opts description kristofferhaugsbakk
2026-08-18 9:57 ` [PATCH v2 2/5] format-rev: place BUG calls first in callback kristofferhaugsbakk
2026-08-18 9:57 ` [PATCH v2 3/5] format-rev: factor option variables into a struct kristofferhaugsbakk
2026-08-18 9:57 ` [PATCH v2 4/5] doc: rev-list-options.adoc: factor out --date alts kristofferhaugsbakk
2026-08-18 9:57 ` [PATCH v2 5/5] format-rev: learn --abbrev, --color, and --date kristofferhaugsbakk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0bd9c642-9e88-4c82-81ee-20fdeb3c2797@app.fastmail.com \
--to=kristofferhaugsbakk@fastmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox