summaryrefslogtreecommitdiff
path: root/t/unit-tests/t-reftable-block.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-10-17 06:53:47 +0200
committerTaylor Blau <me@ttaylorr.com>2024-10-17 16:59:55 -0400
commit7fa7e14ebee9d82545bb4a8dcc1cac22ef51cfed (patch)
tree324fe59913e00241fd7560cbcbd4be39a4efa769 /t/unit-tests/t-reftable-block.c
parent409f04995e6ede838576fb795cf45dc6f10ab508 (diff)
reftable: stop using `strbuf_addf()`
We're about to introduce our own `reftable_buf` type to replace `strbuf`. One function we'll have to convert is `strbuf_addf()`, which is used in a handful of places. This function uses `snprintf()` internally, which makes porting it a bit more involved: - It is not available on all platforms. - Some platforms like Windows have broken implementations. So by using `snprintf()` we'd also push the burden on downstream users of the reftable library to make available a properly working version of it. Most callsites of `strbuf_addf()` are trivial to convert to not using it. We do end up using `snprintf()` in our unit tests, but that isn't much of a problem for downstream users of the reftable library. While at it, remove a useless call to `strbuf_reset()` in `t_reftable_stack_auto_compaction_with_locked_tables()`. We don't write to the buffer before this and initialize it with `STRBUF_INIT`, so there is no need to reset anything. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Taylor Blau <me@ttaylorr.com>
Diffstat (limited to 't/unit-tests/t-reftable-block.c')
-rw-r--r--t/unit-tests/t-reftable-block.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c
index d470060e8b..8077bbc5e7 100644
--- a/t/unit-tests/t-reftable-block.c
+++ b/t/unit-tests/t-reftable-block.c
@@ -308,10 +308,13 @@ static void t_index_block_read_write(void)
check(!ret);
for (i = 0; i < N; i++) {
- strbuf_init(&recs[i].u.idx.last_key, 9);
+ char buf[128];
+
+ snprintf(buf, sizeof(buf), "branch%02"PRIuMAX, (uintmax_t)i);
+ strbuf_init(&recs[i].u.idx.last_key, 9);
recs[i].type = BLOCK_TYPE_INDEX;
- strbuf_addf(&recs[i].u.idx.last_key, "branch%02"PRIuMAX, (uintmax_t)i);
+ strbuf_addstr(&recs[i].u.idx.last_key, buf);
recs[i].u.idx.offset = i;
ret = block_writer_add(&bw, &recs[i]);