aboutsummaryrefslogtreecommitdiffstats
path: root/t/unit-tests
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-01-28 13:02:24 -0800
committerJunio C Hamano <gitster@pobox.com>2025-01-28 13:02:24 -0800
commita17fd7dd3ada289df8e44e64ff52a5d886dfee95 (patch)
treebbc7b3f5eb263b1f40490bf896f38430e7f40c09 /t/unit-tests
parent73e055d71ea39c54e78b6e9a28ea0d8e7999a5cb (diff)
parent33319b0976ff9975e7509b6096887370146893f4 (diff)
downloadgit-a17fd7dd3ada289df8e44e64ff52a5d886dfee95.tar.gz
Merge branch 'ps/reftable-sign-compare'
The reftable/ library code has been made -Wsign-compare clean. * ps/reftable-sign-compare: reftable: address trivial -Wsign-compare warnings reftable/blocksource: adjust `read_block()` to return `ssize_t` reftable/blocksource: adjust type of the block length reftable/block: adjust type of the restart length reftable/block: adapt header and footer size to return a `size_t` reftable/basics: adjust `hash_size()` to return `uint32_t` reftable/basics: adjust `common_prefix_size()` to return `size_t` reftable/record: handle overflows when decoding varints reftable/record: drop unused `print` function pointer meson: stop disabling -Wsign-compare
Diffstat (limited to 't/unit-tests')
-rw-r--r--t/unit-tests/t-reftable-basics.c2
-rw-r--r--t/unit-tests/t-reftable-readwrite.c2
-rw-r--r--t/unit-tests/t-reftable-record.c19
3 files changed, 20 insertions, 3 deletions
diff --git a/t/unit-tests/t-reftable-basics.c b/t/unit-tests/t-reftable-basics.c
index 1d640b280f..9ba7eb05ad 100644
--- a/t/unit-tests/t-reftable-basics.c
+++ b/t/unit-tests/t-reftable-basics.c
@@ -120,7 +120,7 @@ int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
for (size_t i = 0; i < ARRAY_SIZE(cases); i++) {
check(!reftable_buf_addstr(&a, cases[i].a));
check(!reftable_buf_addstr(&b, cases[i].b));
- check_int(common_prefix_size(&a, &b), ==, cases[i].want);
+ check_uint(common_prefix_size(&a, &b), ==, cases[i].want);
reftable_buf_reset(&a);
reftable_buf_reset(&b);
}
diff --git a/t/unit-tests/t-reftable-readwrite.c b/t/unit-tests/t-reftable-readwrite.c
index f22b977563..c9626831da 100644
--- a/t/unit-tests/t-reftable-readwrite.c
+++ b/t/unit-tests/t-reftable-readwrite.c
@@ -643,7 +643,7 @@ static void t_write_empty_table(void)
check_int(err, ==, REFTABLE_EMPTY_TABLE_ERROR);
reftable_writer_free(w);
- check_int(buf.len, ==, header_size(1) + footer_size(1));
+ check_uint(buf.len, ==, header_size(1) + footer_size(1));
block_source_from_buf(&source, &buf);
diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c
index 42bc64cec8..d49d2a2729 100644
--- a/t/unit-tests/t-reftable-record.c
+++ b/t/unit-tests/t-reftable-record.c
@@ -58,9 +58,25 @@ static void t_varint_roundtrip(void)
}
}
+static void t_varint_overflow(void)
+{
+ unsigned char buf[] = {
+ 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0x00,
+ };
+ struct string_view view = {
+ .buf = buf,
+ .len = sizeof(buf),
+ };
+ uint64_t value;
+ int err = get_var_int(&value, &view);
+ check_int(err, ==, -1);
+}
+
static void set_hash(uint8_t *h, int j)
{
- for (int i = 0; i < hash_size(REFTABLE_HASH_SHA1); i++)
+ for (size_t i = 0; i < hash_size(REFTABLE_HASH_SHA1); i++)
h[i] = (j >> i) & 0xff;
}
@@ -544,6 +560,7 @@ int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
TEST(t_reftable_log_record_roundtrip(), "record operations work on log record");
TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record");
TEST(t_varint_roundtrip(), "put_var_int and get_var_int work");
+ TEST(t_varint_overflow(), "get_var_int notices an integer overflow");
TEST(t_key_roundtrip(), "reftable_encode_key and reftable_decode_key work");
TEST(t_reftable_obj_record_roundtrip(), "record operations work on obj record");
TEST(t_reftable_index_record_roundtrip(), "record operations work on index record");