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

[PATCH 1/2] fsck: use enum object_type for fsck_walk callback

From
Jeff King <peff@peff.net>
Date
Aug 19, 2023, 23:53 UTC
Message-ID
<20230819235342.GA600744@coredump.intra.peff.net>
In-Reply-To
<20230819235123.GA600613@coredump.intra.peff.net>

We switched the function interface for fsck callbacks in a1aad71601 (fsck.h: use "enum object_type" instead of "int", 2021-03-28). However, we accidentally flipped the type back to "int" as part of 0b4e9013f1 (fsck: mark unused parameters in various fsck callbacks, 2023-07-03). The mistake happened because that commit was written before a1aad71601 and rebased forward, and I screwed up while resolving the conflict.

Curiously, the compiler does not warn about this mismatch, at least not when using gcc and clang on Linux (nor in any of our CI environments). Based on 28abf260a5 (builtin/fsck.c: don't conflate "int" and "enum" in callback, 2021-06-01), I'd guess that this would cause the AIX xlc compiler to complain. I noticed because clang-18's UBSan now identifies mis-matched function calls at runtime, and does complain of this case when running the test suite.

I'm not entirely clear on whether this mismatch is a problem in practice. Compilers are certainly free to make enums smaller than "int" if they don't need the bits, but I suspect that they have to promote back to int for function calls (though I didn't dig in the standard, and I won't be surprised if I'm simply wrong and the real-world impact would depend on the ABI).

Regardless, switching it back to enum is obviously the right thing to do here; the switch to "int" was simply a mistake.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/fsck.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index c1d0290026..611925905e 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -206,7 +206,7 @@ static int traverse_reachable(void)
 	return !!result;
 }
 
-static int mark_used(struct object *obj, int type UNUSED,
+static int mark_used(struct object *obj, enum object_type type UNUSED,
 		     void *data UNUSED, struct fsck_options *options UNUSED)
 {
 	if (!obj)
-- 
2.42.0.rc2.418.g602d5859fc
Previous: Jeff KingNext: Jeff King
Message 2 of 4 in “fixing a few function pointer mismatches”
  1. 0/2 fixing a few function pointer mismatchesJeff King, Aug 19, 2023
  2. 1/2 fsck: use enum object_type for fsck_walk callbackJeff King, Aug 19, 2023
  3. 2/2 hashmap: use expected signatures for comparison functionsJeff King, Aug 19, 2023
  4. Junio C HamanoAug 20, 2023

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.