]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/options: allow output ret_arg to be omitted
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Tue, 24 Mar 2026 15:26:31 +0000 (16:26 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Wed, 1 Apr 2026 13:34:45 +0000 (15:34 +0200)
Sometimes we have a parser which would never use the argument.

src/shared/options.c

index c5118f33426c32fb4aa037d74afe02245cc5720e..853df0d38d2f1094498d338f9ee63a68b54968ad 100644 (file)
@@ -72,8 +72,6 @@ int option_parse(
                 const Option **ret_option,
                 const char **ret_arg) {
 
-        assert(ret_arg);
-
         /* Check and initialize */
         if (state->optind == 0) {
                 if (state->argc < 1 || strv_isempty(state->argv))
@@ -226,7 +224,13 @@ int option_parse(
         if (ret_option)
                 /* Return the matched Option structure to allow the caller to "know" what was matched */
                 *ret_option = option;
-        *ret_arg = optval;
+
+        if (ret_arg)
+                *ret_arg = optval;
+        else
+                /* It's fine to omit ret_arg, but only if no options return a value. */
+                assert(!optval);
+
         return option->id;
 }