git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] unit-tests: use xstrfmt() instead of a char buffer in t-reftable-stack

From
CPChandra Pratap <chandrapratap3519@gmail.com>
Date
Oct 1, 2024, 17:05 UTC
Message-ID
<20241001170629.7768-1-chandrapratap3519@gmail.com>

A char buffer is used to hold refname values as formatted strings in the reftable_stack_add() test in t/unit-tests/t-reftable-stack.c. This can be replaced with a single call to xstrfmt() making the test conciser.

Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
---
 t/unit-tests/t-reftable-stack.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c
index 31d563d992..2d7cfbf8aa 100644
--- a/t/unit-tests/t-reftable-stack.c
+++ b/t/unit-tests/t-reftable-stack.c
@@ -523,14 +523,12 @@ static void t_reftable_stack_add(void)
 	check(!err);
 
 	for (i = 0; i < N; i++) {
-		char buf[256];
-		snprintf(buf, sizeof(buf), "branch%02"PRIuMAX, (uintmax_t)i);
-		refs[i].refname = xstrdup(buf);
+		refs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
 		refs[i].update_index = i + 1;
 		refs[i].value_type = REFTABLE_REF_VAL1;
 		t_reftable_set_hash(refs[i].value.val1, i, GIT_SHA1_FORMAT_ID);
 
-		logs[i].refname = xstrdup(buf);
+		logs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
 		logs[i].update_index = N + i + 1;
 		logs[i].value_type = REFTABLE_LOG_UPDATE;
 		logs[i].value.update.email = xstrdup("identity@invalid");
-- 
2.45.GIT
Next: Junio C Hamano
Message 1 of 3 in “unit-tests: use xstrfmt() instead of a char buffer in t-reftable-stack”
  1. unit-tests: use xstrfmt() instead of a char buffer in t-reftable-stackChandra Pratap, Oct 1, 2024
  2. Junio C HamanoOct 1, 2024
  3. Eric SunshineOct 1, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.