]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/gc: fix signedness issues in ODB-related functionality
authorPatrick Steinhardt <ps@pks.im>
Mon, 13 Jul 2026 05:52:14 +0000 (07:52 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Jul 2026 15:13:17 +0000 (08:13 -0700)
commit7534d456816d49f20716e49900d43cedb02e8c42
tree2c7f2f2b5dc99f9cb3fc43b92a5b4afdc246c73f
parent0a778894b9676a1e93870589851731dad05e086a
builtin/gc: fix signedness issues in ODB-related functionality

There are a couple of signedness issues in ODB-related functionality.
These are not a problem because we disable -Wsign-compare in this file,
but once we move these functions into "odb/source-files.c" they will
result in warnings.

Fix those issues:

  - In `too_many_loose_objects()` we receive a signed limit, but compare
    it with the unsigned actual number of loose objects. This is fixed
    by bailing out immediately when the limit is smaller than or equal
    to zero, which we also do similarly in other places. The warning is
    then squelched via a cast.

  - In `find_base_packs()` we compare the signed size of the pack
    against the unsigned limit. As the pack size is always going to be a
    positive file size it's safe to cast it to an unsigned value.

  - In `odb_optimize()` we compare the unsigned `keep_pack.nr` value
    against the signed `gc_auto_pack_limit`. We only reach this code
    when `too_many_packs()` returns true-ish, and that can only happen
    when `gc_auto_pack_limit > 0`. Consequently, we can fix the warning
    by casting the limit to an unsigned value.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/gc.c