Re: [PATCH v2 11/18] git-compat-util.h: introduce `u32_add()`
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 22, 2026, 17:07 UTC
- Message-ID
- <xmqq4iodpodf.fsf@gitster.g>
- In-Reply-To
- <014c01dc8b46$7a2997b0$6e7cc710$@nexbridge.com>
<rsbecker@nexbridge.com> writes:
Show 10 quoted lines
>>> This would let the caller handle the failure and is thus quite
>>> flexible, which results in the following code:
>>>
>>> if (!u64_mult(expected_size, (uint64_t)p->pack_size, &expected_size))
>>> die(_("overflow during fixed-point multiply (%"PRIu64" "
>>> "* %"PRIu64")"), expected_size, (uint64_t)p->pack_size);
>>
>>It does read quite cleanly, so I think I'm convinced.
>
> Are all of these changes endian-safe?I do not think of any endian-ness issue around here; these "mult" helpers are checking if the result would overflow using regular division, without doing any funny byte-shuffling ourselves. <git-compat-util.h> has definitions of unsigned_mult_overflows(), and maximum_unsigned_value_of_type(), if you are curious.