From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 66D3A4633B for ; Sat, 15 Jul 2023 10:50:09 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3654E68C73B; Sat, 15 Jul 2023 13:47:02 +0300 (EEST) 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- 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); -- 2.40.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".