Skip to content

Commit 945ebee

Browse files
pks-tgitster
authored andcommitted
reftable/writer: fix type used for number of records
Both `reftable_writer_add_refs()` and `reftable_writer_add_logs()` accept an array of records that should be added to the new table. Callers of this function are expected to also pass the number of such records to the function to tell it how many such records it is supposed to write. But while all callers pass in a `size_t`, which is a sensible choice, the function in fact accepts an `int` as argument, which is less so. Fix this. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e813a02 commit 945ebee

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

reftable/reftable-writer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ int reftable_writer_add_ref(struct reftable_writer *w,
156156
the records before adding them, reordering the records array passed in.
157157
*/
158158
int reftable_writer_add_refs(struct reftable_writer *w,
159-
struct reftable_ref_record *refs, int n);
159+
struct reftable_ref_record *refs, size_t n);
160160

161161
/*
162162
adds reftable_log_records. Log records are keyed by (refname, decreasing
@@ -171,7 +171,7 @@ int reftable_writer_add_log(struct reftable_writer *w,
171171
the records before adding them, reordering records array passed in.
172172
*/
173173
int reftable_writer_add_logs(struct reftable_writer *w,
174-
struct reftable_log_record *logs, int n);
174+
struct reftable_log_record *logs, size_t n);
175175

176176
/* reftable_writer_close finalizes the reftable. The writer is retained so
177177
* statistics can be inspected. */

reftable/writer.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,15 @@ int reftable_writer_add_ref(struct reftable_writer *w,
395395
}
396396

397397
int reftable_writer_add_refs(struct reftable_writer *w,
398-
struct reftable_ref_record *refs, int n)
398+
struct reftable_ref_record *refs, size_t n)
399399
{
400400
int err = 0;
401-
int i = 0;
401+
402402
QSORT(refs, n, reftable_ref_record_compare_name);
403-
for (i = 0; err == 0 && i < n; i++) {
403+
404+
for (size_t i = 0; err == 0 && i < n; i++)
404405
err = reftable_writer_add_ref(w, &refs[i]);
405-
}
406+
406407
return err;
407408
}
408409

@@ -486,15 +487,15 @@ int reftable_writer_add_log(struct reftable_writer *w,
486487
}
487488

488489
int reftable_writer_add_logs(struct reftable_writer *w,
489-
struct reftable_log_record *logs, int n)
490+
struct reftable_log_record *logs, size_t n)
490491
{
491492
int err = 0;
492-
int i = 0;
493+
493494
QSORT(logs, n, reftable_log_record_compare_key);
494495

495-
for (i = 0; err == 0 && i < n; i++) {
496+
for (size_t i = 0; err == 0 && i < n; i++)
496497
err = reftable_writer_add_log(w, &logs[i]);
497-
}
498+
498499
return err;
499500
}
500501

0 commit comments

Comments
 (0)