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

[PATCH 6/6] reflog: assert PARSE_OPT_NONEG in parse-options callbacks

From
Jeff King <peff@peff.net>
Date
Aug 19, 2022, 08:55 UTC
Message-ID
<Yv9P5l6ku3ZyG6yR@coredump.intra.peff.net>
In-Reply-To
<Yv9Oay+tNqhLDqVl@coredump.intra.peff.net>

In the spirit of 517fe807d6 (assert NOARG/NONEG behavior of parse-options callbacks, 2018-11-05), this asserts that our callbacks were invoked using the right flags (since otherwise they'd segfault on the NULL arg). Both cases are already correct here, so this is mostly about annotating the functions, and appeasing -Wunused-parameters.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/reflog.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 4dd297dce8..8123956847 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -193,6 +193,8 @@ static int expire_unreachable_callback(const struct option *opt,
 {
 	struct cmd_reflog_expire_cb *cmd = opt->value;
 
+	BUG_ON_OPT_NEG(unset);
+
 	if (parse_expiry_date(arg, &cmd->expire_unreachable))
 		die(_("invalid timestamp '%s' given to '--%s'"),
 		    arg, opt->long_name);
@@ -207,6 +209,8 @@ static int expire_total_callback(const struct option *opt,
 {
 	struct cmd_reflog_expire_cb *cmd = opt->value;
 
+	BUG_ON_OPT_NEG(unset);
+
 	if (parse_expiry_date(arg, &cmd->expire_total))
 		die(_("invalid timestamp '%s' given to '--%s'"),
 		    arg, opt->long_name);
-- 
2.37.2.928.g0821088f4a
Previous: Han-Wen NienhuysNext: Derrick Stolee
Message 19 of 21 in “unused function parameter potpourri”
  1. 0/6 unused function parameter potpourriJeff King, Aug 19, 2022
  2. 1/6 xdiff: drop unused mmfile parameters from xdl_do_histogram_diff()Jeff King, Aug 19, 2022
  3. Phillip WoodAug 19, 2022
  4. Jeff KingAug 20, 2022
  5. 7/6 xdiff: drop unused mmfile parameters from xdl_do_patience_diff()Jeff King, Aug 20, 2022
  6. Phillip WoodAug 26, 2022
  7. 2/6 log-tree: drop unused commit param in remerge_diff()Jeff King, Aug 19, 2022
  8. Elijah NewrenAug 19, 2022
  9. Jeff KingAug 20, 2022
  10. 3/6 match_pathname(): drop unused "flags" parameterJeff King, Aug 19, 2022
  11. 4/6 verify_one_sparse(): drop unused repository parameterJeff King, Aug 19, 2022
  12. Derrick StoleeAug 19, 2022
  13. Jeff KingAug 20, 2022
  14. René ScharfeAug 20, 2022
  15. 4/6 verify_one_sparse(): drop unused repository parameterJeff King, Aug 20, 2022
  16. 5/6 reftable: drop unused parameter from reader_seek_linear()Jeff King, Aug 19, 2022
  17. Derrick StoleeAug 19, 2022
  18. Han-Wen NienhuysAug 22, 2022
  19. 6/6 reflog: assert PARSE_OPT_NONEG in parse-options callbacksJeff King, Aug 19, 2022
  20. Derrick StoleeAug 19, 2022
  21. Elijah NewrenAug 19, 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.