Thread (17 messages) flat view 17 messages, 2 authors, 3d ago
WARM3d

Revision v2 of 2 in this series.

Revisions (2)
  1. v1 [diff vs current]
  2. v2 current

[PATCH v2 2/5] format-rev: place BUG calls first in callback

From: <hidden>
Date: 2026-08-18 09:58:27
Subsystem: the rest · Maintainer: Linus Torvalds

From: Kristoffer Haugsbakk <redacted>

I added these parse-options `BUG` statements based on existing examples;
one `BUG` check per flag. Now, of course the code as-is will not call
this callback with `unset` set to `0`, or with an argument
string. Rather, these preconditions defend against `opts[]` getting
changed *without* changing this callback.

And I copied the existing examples that I found down to
the placement. And the placement doesn’t matter here; we just
unconditionally set two variables. Failing on `BUG` before or after
that makes no difference to the user. Still, it is better style to
test function preconditions as early as possible. So let’s move them
to the start.

Signed-off-by: Kristoffer Haugsbakk <redacted>
---

Notes (series):
    v2: • [new]
        • https://lore.kernel.org/git/0bd9c642-9e88-4c82-81ee-20fdeb3c2797@app.fastmail.com/ (local)

 builtin/name-rev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 254c88199fd..d6686bbdbb9 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -782,10 +782,10 @@ static int format_nul_cb(const struct option *option,
 			 int unset)
 {
 	struct format_nul_data *data = option->value;
-	data->nul_input = 1;
-	data->nul_output = 1;
 	BUG_ON_OPT_NEG(unset);
 	BUG_ON_OPT_ARG(arg);
+	data->nul_input = 1;
+	data->nul_output = 1;
 	return 0;
 }
 
-- 
2.55.0.13.g85d2d65e389
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help