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

[PATCH 1/4] test-submodule: inline resolve_relative_url() function

From
Jeff King <peff@peff.net>
Date
Oct 6, 2022, 13:10 UTC
Message-ID
<Yz7Tt4ezU/GS3tHu@coredump.intra.peff.net>
In-Reply-To
<Yz7Tjy7Rh8cXVxYQ@coredump.intra.peff.net>

The resolve_relative_url() function takes argc and argv parameters; it then reads up to 3 elements of argv without looking at argc at all. At first glance, this seems like a bug. But it has only one caller, cmd__submodule_resolve_relative_url(), which does confirm that argc is 3.

The main reason this is a separate function is that it was moved from library code in 96a28a9bc6 (submodule--helper: move "resolve-relative-url-test" to a test-tool, 2022-09-01).

We can make this code simpler and more obviously safe by just inlining the function in its caller. As a bonus, this silences a -Wunused-parameter warning.

Signed-off-by: Jeff King <peff@peff.net>
---
 t/helper/test-submodule.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c
index e0e0c53d38..b7d117cd55 100644
--- a/t/helper/test-submodule.c
+++ b/t/helper/test-submodule.c
@@ -85,10 +85,17 @@ static int cmd__submodule_is_active(int argc, const char **argv)
 	return !is_submodule_active(the_repository, argv[0]);
 }
 
-static int resolve_relative_url(int argc, const char **argv)
+static int cmd__submodule_resolve_relative_url(int argc, const char **argv)
 {
 	char *remoteurl, *res;
 	const char *up_path, *url;
+	struct option options[] = {
+		OPT_END()
+	};
+	argc = parse_options(argc, argv, "test-tools", options,
+			     submodule_resolve_relative_url_usage, 0);
+	if (argc != 3)
+		usage_with_options(submodule_resolve_relative_url_usage, options);
 
 	up_path = argv[0];
 	remoteurl = xstrdup(argv[1]);
@@ -104,19 +111,6 @@ static int resolve_relative_url(int argc, const char **argv)
 	return 0;
 }
 
-static int cmd__submodule_resolve_relative_url(int argc, const char **argv)
-{
-	struct option options[] = {
-		OPT_END()
-	};
-	argc = parse_options(argc, argv, "test-tools", options,
-			     submodule_resolve_relative_url_usage, 0);
-	if (argc != 3)
-		usage_with_options(submodule_resolve_relative_url_usage, options);
-
-	return resolve_relative_url(argc, argv);
-}
-
 static struct test_cmd cmds[] = {
 	{ "check-name", cmd__submodule_check_name },
 	{ "is-active", cmd__submodule_is_active },
-- 
2.38.0.661.g581b1c9920
Previous: Jeff KingNext: Jeff King
Message 2 of 11 in “a few small unused-parameter fixes”
  1. 0/4 a few small unused-parameter fixesJeff King, Oct 6, 2022
  2. 1/4 test-submodule: inline resolve_relative_url() functionJeff King, Oct 6, 2022
  3. 2/4 multi-pack-index: avoid writing to global in option callbackJeff King, Oct 6, 2022
  4. 3/4 commit: avoid writing to global in option callbackJeff King, Oct 6, 2022
  5. 4/4 attr: convert DEBUG_ATTR to use trace APIJeff King, Oct 6, 2022
  6. attr: drop DEBUG_ATTR codeJeff King, Oct 6, 2022
  7. Junio C HamanoOct 6, 2022
  8. Derrick StoleeOct 6, 2022
  9. Junio C HamanoOct 6, 2022
  10. Jeff KingOct 11, 2022
  11. Jeff KingOct 11, 2022

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.