From patchwork Sat Jul 15 10:45:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42718 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240220pzb; Sat, 15 Jul 2023 03:50:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlEII3fuxGcNZSRRdp0g+pG4DYCSCB15lUQhZXWn0+llp2NGM0yWUmjftFiNLSL1xgqwUFIF X-Received: by 2002:a50:ef0e:0:b0:521:6ed7:aab1 with SMTP id m14-20020a50ef0e000000b005216ed7aab1mr2510551eds.7.1689418212267; Sat, 15 Jul 2023 03:50:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418212; cv=none; d=google.com; s=arc-20160816; b=0rrcfUqwG1IM9t6uBTT3yDITxPWoFZTtvnMlx4iDMvIcQMnNmpAATqIGcNd05yKEqY rQSxWWusMHwNPSNMNKAmZmtdbP+673BlQYVrkXpXh/lUGOE59WLNEgB/VF/oZ3mPFpMo /kLv+oMvXJDEydbXIYOMP0JIp1rRliRtHYGN6TSXGI4NWryDmKWjkOXy4tUg2zGltL+8 terp/QTUsk113w7kMFJ+WYs49BeZGtlVMpB2cVZEF4YCgCwA2PQxnhExmz8owMDrt8CZ BDg4muHrqSNn8y6Z8lhPeY2jH88+4eeifRjEWEYNtyKaE3nde7d/vt5Agcy3VYE/VxYw bHRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=4WD0FAgnWKdww0k+p6pM41t03emo/9rfiqnaXkG8C7s=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=xnYOopVdZfq6UBloXKxUNXrVQLRdw/JqphHgFlRb7ymxOsmrJqUbwFoxY+poe/Gdys k3OaRfbNXbTbaeiVIVyDPb+ie4KNxBOi+u8y4V81OWLresUbJ4gmtkkdoAdC6PXs3dzM f+9rCum+gLE2hItMm7aZt/61LLUg9kDzt2gF2s0C6aQf4aQSvsI0EHY3Jja5SqofWo2E kzDsEyUNdi+ws6qd86OjsvI6msVNksjE7mzdT48ac+ogfEGOSEQmIib9l8pdrnMU3rkU XWmMRN73hfxkvDeWpDdHXp4ft7ntFjUBQeP0V5pxZ4/H+F3J6ygjARvihpeSRCtk/XzV d4Fg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e8-20020a056402088800b0051e196bf9ddsi10796067edy.375.2023.07.15.03.50.11; Sat, 15 Jul 2023 03:50:12 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 68FE168C73C; Sat, 15 Jul 2023 13:47:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4707468C69D for ; Sat, 15 Jul 2023 13:46:42 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EEA002404EA for ; Sat, 15 Jul 2023 12:46:41 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id NHw9VibbOXAP for ; Sat, 15 Jul 2023 12:46:41 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 12CD7240D23 for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 89C323A2307 for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:58 +0200 Message-Id: <20230715104611.17902-34-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 34/47] fftools: handle errors in parse_options() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: PUE2Pvwso7kv --- fftools/cmdutils.c | 15 ++++++++++----- fftools/cmdutils.h | 4 ++-- fftools/ffplay.c | 12 ++++++++---- fftools/ffprobe.c | 10 +++++++--- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index b401b8fb89..330b9c2aba 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -364,8 +364,8 @@ int parse_option(void *optctx, const char *opt, const char *arg, return !!(po->flags & HAS_ARG); } -void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, - void (*parse_arg_function)(void *, const char*)) +int parse_options(void *optctx, int argc, char **argv, const OptionDef *options, + int (*parse_arg_function)(void *, const char*)) { const char *opt; int optindex, handleoptions = 1, ret; @@ -386,13 +386,18 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options opt++; if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0) - exit_program(1); + return ret; optindex += ret; } else { - if (parse_arg_function) - parse_arg_function(optctx, opt); + if (parse_arg_function) { + ret = parse_arg_function(optctx, opt); + if (ret < 0) + return ret; + } } } + + return 0; } int parse_optgroup(void *optctx, OptionGroup *g) diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index dc041d9fa2..210d52e998 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -194,8 +194,8 @@ void show_help_default(const char *opt, const char *arg); * argument without a leading option name flag. NULL if such arguments do * not have to be processed. */ -void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, - void (* parse_arg_function)(void *optctx, const char*)); +int parse_options(void *optctx, int argc, char **argv, const OptionDef *options, + int (* parse_arg_function)(void *optctx, const char*)); /** * Parse one given option. diff --git a/fftools/ffplay.c b/fftools/ffplay.c index 89cea4d876..4e26b3309d 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -3501,17 +3501,19 @@ static int opt_show_mode(void *optctx, const char *opt, const char *arg) return 0; } -static void opt_input_file(void *optctx, const char *filename) +static int opt_input_file(void *optctx, const char *filename) { if (input_filename) { av_log(NULL, AV_LOG_FATAL, "Argument '%s' provided as input filename, but '%s' was already specified.\n", filename, input_filename); - exit(1); + return AVERROR(EINVAL); } if (!strcmp(filename, "-")) filename = "fd:"; input_filename = filename; + + return 0; } static int opt_codec(void *optctx, const char *opt, const char *arg) @@ -3630,7 +3632,7 @@ void show_help_default(const char *opt, const char *arg) /* Called from the main */ int main(int argc, char **argv) { - int flags; + int flags, ret; VideoState *is; init_dynload(); @@ -3649,7 +3651,9 @@ int main(int argc, char **argv) show_banner(argc, argv, options); - parse_options(NULL, argc, argv, options, opt_input_file); + ret = parse_options(NULL, argc, argv, options, opt_input_file); + if (ret < 0) + exit(1); if (!input_filename) { show_usage(); diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index e6fd33492d..ba55437760 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -3770,17 +3770,19 @@ static int opt_show_entries(void *optctx, const char *opt, const char *arg) return ret; } -static void opt_input_file(void *optctx, const char *arg) +static int opt_input_file(void *optctx, const char *arg) { if (input_filename) { av_log(NULL, AV_LOG_ERROR, "Argument '%s' provided as input filename, but '%s' was already specified.\n", arg, input_filename); - exit_program(1); + return AVERROR(EINVAL); } if (!strcmp(arg, "-")) arg = "fd:"; input_filename = arg; + + return 0; } static int opt_input_file_i(void *optctx, const char *opt, const char *arg) @@ -4121,7 +4123,9 @@ int main(int argc, char **argv) #endif show_banner(argc, argv, options); - parse_options(NULL, argc, argv, options, opt_input_file); + ret = parse_options(NULL, argc, argv, options, opt_input_file); + if (ret < 0) + exit_program(1); if (do_show_log) av_log_set_callback(log_callback);