reftable/block: adjust type of the restart length
The restart length is tracked as a positive integer even though it cannot ever be negative. Furthermore, it is effectively capped via the MAX_RESTARTS variable. Adjust the type of the variable to be `uint32_t`. While this type is excessive given that MAX_RESTARTS fits into an `uint16_t`, other places already use 32 bit integers for restarts, so this type is being more consistent. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Jan 20, 2025 at 17:17 UTC
b1e4b6f4dc27481e8c07acc2e7629ae206d25f6c
2 files changed
+6
-8
reftable/block.c
+5
-7
@@ -40,16 +40,15 @@ size_t footer_size(int version)
40
static int block_writer_register_restart(struct block_writer *w, int n,
41
int is_restart, struct reftable_buf *key)
42
{
43
- int rlen, err;
43
+ uint32_t rlen;
44
+ int err;
45
46
rlen = w->restart_len;
46
- if (rlen >= MAX_RESTARTS) {
47
+ if (rlen >= MAX_RESTARTS)
48
is_restart = 0;
48
- }
49
50
- if (is_restart) {
50
+ if (is_restart)
51
rlen++;
52
- }
52
if (2 + 3 * rlen + n > w->block_size - w->next)
53
return -1;
54
if (is_restart) {
@@ -148,8 +147,7 @@ done:
147
148
int block_writer_finish(struct block_writer *w)
149
{
151
- int i;
152
- for (i = 0; i < w->restart_len; i++) {
150
+ for (uint32_t i = 0; i < w->restart_len; i++) {
151
put_be24(w->block + w->next, w->restarts[i]);
152
w->next += 3;
153
}
reftable/reftable-writer.h
+1
-1
@@ -84,7 +84,7 @@ struct reftable_block_stats {
84
/* total number of entries written */
85
int entries;
86
/* total number of key restarts */
87
- int restarts;
87
+ uint32_t restarts;
88
/* total number of blocks */
89
int blocks;
90
/* total number of index blocks */