Skip to content

Commit 581a3bb

Browse files
rscharfegitster
authored andcommitted
object-file: use unsigned arithmetic with bit mask
33f379e (make object_directory.loose_objects_subdir_seen a bitmap, 2021-07-07) replaced a wasteful 256-byte array with a 32-byte array and bit operations. The mask calculation shifts a literal 1 of type int left by anything between 0 and 31. UndefinedBehaviorSanitizer doesn't like that and reports: object-file.c:2477:18: runtime error: left shift of 1 by 31 places cannot be represented in type 'int' Make sure to use an unsigned 1 instead to avoid the issue. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dd3c8a7 commit 581a3bb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

object-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2463,7 +2463,7 @@ struct oidtree *odb_loose_cache(struct object_directory *odb,
24632463
struct strbuf buf = STRBUF_INIT;
24642464
size_t word_bits = bitsizeof(odb->loose_objects_subdir_seen[0]);
24652465
size_t word_index = subdir_nr / word_bits;
2466-
size_t mask = 1 << (subdir_nr % word_bits);
2466+
size_t mask = 1u << (subdir_nr % word_bits);
24672467
uint32_t *bitmap;
24682468

24692469
if (subdir_nr < 0 ||

0 commit comments

Comments
 (0)