From ebdbbd3213366d764522524b22f739eee7889b8b Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 9 Apr 2021 12:48:30 -0400 Subject: [PATCH] Fix: argpar: Error out when passing an argument to long option that takes no argument MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If the user defines a long option `--foo` and passes `--foo=arg`, the current behavior is that the option foo is recognized and the argument is ignored. Change that to be an error. It is currently not possible to pass arguments to short options using an equal sign, so this doesn't apply to short options. Equivalent accepted change in argpar: https://review.lttng.org/c/argpar/+/5361 Change-Id: I6fd6271abb7e271704db1e60f680729931a1fbe1 Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau --- src/common/argpar/argpar.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/common/argpar/argpar.c b/src/common/argpar/argpar.c index bf19808c5..68bb5a426 100644 --- a/src/common/argpar/argpar.c +++ b/src/common/argpar/argpar.c @@ -477,6 +477,15 @@ enum parse_orig_arg_opt_ret parse_long_opt(const char * const long_opt_arg, opt_arg = next_orig_arg; used_next_orig_arg = true; } + } else if (eq_pos) { + /* + * Unexpected `--opt=arg` style for a long option which + * doesn't accept an argument. + */ + argpar_string_append_printf(error, + "Unexpected argument for option `--%s`", + long_opt_name); + goto error; } /* Create and append option argument */ -- 2.34.1