From: Jeff King <peff@peff•net>
To: Junio C Hamano <gitster@pobox•com>
Cc: Justin Tobler <jltobler@gmail•com>, git@vger•kernel.org
Subject: Re: [PATCH] object-file: use `container_of()` to convert from base types
Date: Sun, 22 Feb 2026 04:41:58 -0500 [thread overview]
Message-ID: <20260222094158.GA1319383@coredump.intra.peff.net> (raw)
In-Reply-To: <xmqqms11qmsj.fsf@gitster.g>
On Sat, Feb 21, 2026 at 11:07:08PM -0800, Junio C Hamano wrote:
> Perhaps a fix-up patch on top of the topic branch like this?
>
> ----- >8 -----
> Subject: [PATCH] object-file.c: avoid container_of() of a NULL container
> [...]
> static void prepare_loose_object_transaction(struct odb_transaction *base)
> {
> - struct odb_transaction_files *transaction =
> - container_of(base, struct odb_transaction_files, base);
> + struct odb_transaction_files *transaction = NULL;
> +
> + if (base)
> + transaction =
> + container_of(base, struct odb_transaction_files, base);
That works, but you can also use container_of_or_null() in the
initializer. IMHO the result is easier to read.
-Peff
next prev parent reply other threads:[~2026-02-22 9:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-18 21:01 [PATCH] object-file: use `container_of()` to convert from base types Justin Tobler
2026-02-19 13:43 ` Patrick Steinhardt
2026-02-20 16:07 ` Toon Claes
2026-02-22 7:07 ` Junio C Hamano
2026-02-22 9:41 ` Jeff King [this message]
2026-02-22 17:19 ` Justin Tobler
2026-02-22 20:36 ` Junio C Hamano
2026-02-22 20:16 ` [PATCH] object-file.c: avoid container_of() of a NULL container Junio C Hamano
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=20260222094158.GA1319383@coredump.intra.peff.net \
--to=peff@peff$(echo .)net \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
--cc=jltobler@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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