Skip to content

Commit b1e4b6f

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ffe6643 commit b1e4b6f

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

reftable/block.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,15 @@ size_t footer_size(int version)
4040
static int block_writer_register_restart(struct block_writer *w, int n,
4141
int is_restart, struct reftable_buf *key)
4242
{
43-
int rlen, err;
43+
uint32_t rlen;
44+
int err;
4445

4546
rlen = w->restart_len;
46-
if (rlen >= MAX_RESTARTS) {
47+
if (rlen >= MAX_RESTARTS)
4748
is_restart = 0;
48-
}
4949

50-
if (is_restart) {
50+
if (is_restart)
5151
rlen++;
52-
}
5352
if (2 + 3 * rlen + n > w->block_size - w->next)
5453
return -1;
5554
if (is_restart) {
@@ -148,8 +147,7 @@ int block_writer_add(struct block_writer *w, struct reftable_record *rec)
148147

149148
int block_writer_finish(struct block_writer *w)
150149
{
151-
int i;
152-
for (i = 0; i < w->restart_len; i++) {
150+
for (uint32_t i = 0; i < w->restart_len; i++) {
153151
put_be24(w->block + w->next, w->restarts[i]);
154152
w->next += 3;
155153
}

reftable/reftable-writer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct reftable_block_stats {
8484
/* total number of entries written */
8585
int entries;
8686
/* total number of key restarts */
87-
int restarts;
87+
uint32_t restarts;
8888
/* total number of blocks */
8989
int blocks;
9090
/* total number of index blocks */

0 commit comments

Comments
 (0)