]> git.ipfire.org Git - thirdparty/git.git/commitdiff
reftable/writer: fix type used for number of records
authorPatrick Steinhardt <ps@pks.im>
Tue, 12 Aug 2025 09:54:15 +0000 (11:54 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 12 Aug 2025 14:40:58 +0000 (07:40 -0700)
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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reftable/reftable-writer.h
reftable/writer.c

index 0fbeff17f462edfd6cd61d49cc2a9adc7310f30e..1e7003cd698879ced874260c308d9cac06650a91 100644 (file)
@@ -156,7 +156,7 @@ int reftable_writer_add_ref(struct reftable_writer *w,
   the records before adding them, reordering the records array passed in.
 */
 int reftable_writer_add_refs(struct reftable_writer *w,
-                            struct reftable_ref_record *refs, int n);
+                            struct reftable_ref_record *refs, size_t n);
 
 /*
   adds reftable_log_records. Log records are keyed by (refname, decreasing
@@ -171,7 +171,7 @@ int reftable_writer_add_log(struct reftable_writer *w,
   the records before adding them, reordering records array passed in.
 */
 int reftable_writer_add_logs(struct reftable_writer *w,
-                            struct reftable_log_record *logs, int n);
+                            struct reftable_log_record *logs, size_t n);
 
 /* reftable_writer_close finalizes the reftable. The writer is retained so
  * statistics can be inspected. */
index 3b4ebdd6dced348dd16ccdaa70c506acbfdb1e4d..5bad130c7ed09dcab9e7b98798e2a47ec66534e1 100644 (file)
@@ -395,14 +395,15 @@ out:
 }
 
 int reftable_writer_add_refs(struct reftable_writer *w,
-                            struct reftable_ref_record *refs, int n)
+                            struct reftable_ref_record *refs, size_t n)
 {
        int err = 0;
-       int i = 0;
+
        QSORT(refs, n, reftable_ref_record_compare_name);
-       for (i = 0; err == 0 && i < n; i++) {
+
+       for (size_t i = 0; err == 0 && i < n; i++)
                err = reftable_writer_add_ref(w, &refs[i]);
-       }
+
        return err;
 }
 
@@ -486,15 +487,15 @@ done:
 }
 
 int reftable_writer_add_logs(struct reftable_writer *w,
-                            struct reftable_log_record *logs, int n)
+                            struct reftable_log_record *logs, size_t n)
 {
        int err = 0;
-       int i = 0;
+
        QSORT(logs, n, reftable_log_record_compare_key);
 
-       for (i = 0; err == 0 && i < n; i++) {
+       for (size_t i = 0; err == 0 && i < n; i++)
                err = reftable_writer_add_log(w, &logs[i]);
-       }
+
        return err;
 }