object-file.c: avoid container_of() of a NULL container

Even though the "struct odb_transaction" member is at the beginning of the containing "struct odb_transaction_files", i.e., at offset 0, using container_of() to add offset 0 to a NULL pointer gets flagged as a bad behaviour under SANITIZE=undefined. Use container_of_or_null() to work around this issue. Helped-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Feb 22, 2026 at 12:16 UTC 8e06f961d7290e2fd31ea008b00b7a1ed1c904b5
1 file changed +2 -2
object-file.c
+2 -2
@@ -720,7 +720,7 @@ struct odb_transaction_files {
720 static void prepare_loose_object_transaction(struct odb_transaction *base)
721 {
722 struct odb_transaction_files *transaction =
723 - container_of(base, struct odb_transaction_files, base);
723 + container_of_or_null(base, struct odb_transaction_files, base);
724
725 /*
726 * We lazily create the temporary object directory
@@ -740,7 +740,7 @@ static void fsync_loose_object_transaction(struct odb_transaction *base,
740 int fd, const char *filename)
741 {
742 struct odb_transaction_files *transaction =
743 - container_of(base, struct odb_transaction_files, base);
743 + container_of_or_null(base, struct odb_transaction_files, base);
744
745 /*
746 * If we have an active ODB transaction, we issue a call that