On 09/05/2025 07:19, Patrick Steinhardt wrote:
All of that starts to become kind of involved though. So unless others disagree with my analysis I just don't think this edge case really is worth the complexity.
I agree with this. We seem to be copying the string because argv is a const char** but would it really be so bad to modify the string that gets passed to us? We know that any bundled options that come before an unknown option cannot have a value or else what we see as the unknown option would be part of that value. So I think we could do diff --git a/parse-options.c b/parse-options.c index 35fbb3b0d6..9e6e46da27 100644 --- a/parse-options.c +++ b/parse-options.c @@ -924,12 +924,12 @@ enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx, if (internal_help && *ctx->opt == 'h') goto show_usage; - /* fake a short option thing to hide the fact that we may have + /* move a short option thing to hide the fact that we may have * started to parse aggregated stuff - * - * This is leaky, too bad. */ - ctx->argv[0] = xstrdup(ctx->opt - 1); + MOVE_ARRAY((char *)arg, ctx->opt - 1, + strlen(ctx->opt) + 2); + ctx->argv[0] = arg; *(char *)ctx->argv[0] = '-'; goto unknown; case PARSE_OPT_NON_OPTION: Best Wishes Phillip