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

[PATCH v2 06/10] reftable/block: adapt header and footer size to return a `size_t`

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 20, 2025, 16:17 UTC
Message-ID
<20250120-b4-pks-reftable-sign-compare-v2-6-b4566d02e4a5@pks.im>
In-Reply-To
<20250120-b4-pks-reftable-sign-compare-v2-0-b4566d02e4a5@pks.im>

The functions `header_size()` and `footer_size()` return a positive integer representing the size of the header and footer, respectively, dependent on the version of the reftable format. Similar to the preceding commit, these functions return a signed integer though, which is nonsensical given that there is no way for these functions to return negative.

Adapt the functions to return a `size_t` instead to fix a couple of sign comparison warnings.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 reftable/block.c                    | 4 ++--
 reftable/block.h                    | 4 ++--
 t/unit-tests/t-reftable-readwrite.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/reftable/block.c b/reftable/block.c
index 2380aabb2f..1275085257 100644
--- a/reftable/block.c
+++ b/reftable/block.c
@@ -15,7 +15,7 @@ license that can be found in the LICENSE file or at
 #include "system.h"
 #include <zlib.h>
 
-int header_size(int version)
+size_t header_size(int version)
 {
 	switch (version) {
 	case 1:
@@ -26,7 +26,7 @@ int header_size(int version)
 	abort();
 }
 
-int footer_size(int version)
+size_t footer_size(int version)
 {
 	switch (version) {
 	case 1:
diff --git a/reftable/block.h b/reftable/block.h
index 5f67ed74c5..bef2b8a4c5 100644
--- a/reftable/block.h
+++ b/reftable/block.h
@@ -137,10 +137,10 @@ void block_iter_reset(struct block_iter *it);
 void block_iter_close(struct block_iter *it);
 
 /* size of file header, depending on format version */
-int header_size(int version);
+size_t header_size(int version);
 
 /* size of file footer, depending on format version */
-int footer_size(int version);
+size_t footer_size(int version);
 
 /* returns a block to its source. */
 void reftable_block_done(struct reftable_block *ret);
diff --git a/t/unit-tests/t-reftable-readwrite.c b/t/unit-tests/t-reftable-readwrite.c
index 6b75a419b9..2e553154ea 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);
 
-- 
2.48.0.257.gd3603152ad.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 24 of 28 in “reftable: fix -Wsign-compare warnings”
  1. 00/10 reftable: fix -Wsign-compare warningsPatrick Steinhardt, Jan 16, 2025
  2. 01/10 meson: stop disabling -Wsign-comparePatrick Steinhardt, Jan 16, 2025
  3. 02/10 reftable/record: drop unused `print` function pointerPatrick Steinhardt, Jan 16, 2025
  4. 03/10 reftable/record: handle overflows when decoding varintsPatrick Steinhardt, Jan 16, 2025
  5. Karthik NayakJan 20, 2025
  6. Patrick SteinhardtJan 20, 2025
  7. 04/10 reftable/basics: adjust `common_prefix_size()` to return `size_t`Patrick Steinhardt, Jan 16, 2025
  8. 05/10 reftable/basics: adjust `hash_size()` to return `uint32_t`Patrick Steinhardt, Jan 16, 2025
  9. 06/10 reftable/block: adapt header and footer size to return a `size_t`Patrick Steinhardt, Jan 16, 2025
  10. 07/10 reftable/block: adjust type of the restart lengthPatrick Steinhardt, Jan 16, 2025
  11. 08/10 reftable/blocksource: adjust type of the block lengthPatrick Steinhardt, Jan 16, 2025
  12. 09/10 reftable/blocksource: adjust `read_block()` to return `ssize_t`Patrick Steinhardt, Jan 16, 2025
  13. 10/10 reftable: address trivial -Wsign-compare warningsPatrick Steinhardt, Jan 16, 2025
  14. Junio C HamanoJan 16, 2025
  15. Patrick SteinhardtJan 17, 2025
  16. Karthik NayakJan 20, 2025
  17. Patrick SteinhardtJan 20, 2025
  18. 00/10 reftable: fix -Wsign-compare warningsPatrick Steinhardt, Jan 20, 2025
  19. 01/10 meson: stop disabling -Wsign-comparePatrick Steinhardt, Jan 20, 2025
  20. 02/10 reftable/record: drop unused `print` function pointerPatrick Steinhardt, Jan 20, 2025
  21. 03/10 reftable/record: handle overflows when decoding varintsPatrick Steinhardt, Jan 20, 2025
  22. 04/10 reftable/basics: adjust `common_prefix_size()` to return `size_t`Patrick Steinhardt, Jan 20, 2025
  23. 05/10 reftable/basics: adjust `hash_size()` to return `uint32_t`Patrick Steinhardt, Jan 20, 2025
  24. 06/10 reftable/block: adapt header and footer size to return a `size_t`Patrick Steinhardt, Jan 20, 2025
  25. 07/10 reftable/block: adjust type of the restart lengthPatrick Steinhardt, Jan 20, 2025
  26. 08/10 reftable/blocksource: adjust type of the block lengthPatrick Steinhardt, Jan 20, 2025
  27. 09/10 reftable/blocksource: adjust `read_block()` to return `ssize_t`Patrick Steinhardt, Jan 20, 2025
  28. 10/10 reftable: address trivial -Wsign-compare warningsPatrick Steinhardt, Jan 20, 2025

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.