summaryrefslogtreecommitdiff
path: root/fftools/cmdutils.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2023-07-14 13:47:23 +0200
committerAnton Khirnov <anton@khirnov.net>2023-07-20 20:47:40 +0200
commit9cb47c78d66c0d8abf5dbedd254d3761d5c5b06a (patch)
tree1cb27929156e937ac021d69574f7203f29fd168c /fftools/cmdutils.c
parent4adbe2d219c13d5342d073aace5001a64c57d9c8 (diff)
fftools: return errors from parse_number_or_die() instead of aborting
Rename the function to just parse_number().
Diffstat (limited to 'fftools/cmdutils.c')
-rw-r--r--fftools/cmdutils.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index fb35245f0a..8afa9400cc 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -104,8 +104,8 @@ void exit_program(int ret)
exit(ret);
}
-double parse_number_or_die(const char *context, const char *numstr, int type,
- double min, double max)
+int parse_number(const char *context, const char *numstr, int type,
+ double min, double max, double *dst)
{
char *tail;
const char *error;
@@ -118,11 +118,13 @@ double parse_number_or_die(const char *context, const char *numstr, int type,
error = "Expected int64 for %s but found %s\n";
else if (type == OPT_INT && (int)d != d)
error = "Expected int for %s but found %s\n";
- else
- return d;
+ else {
+ *dst = d;
+ return 0;
+ }
+
av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
- exit_program(1);
- return 0;
+ return AVERROR(EINVAL);
}
int64_t parse_time_or_die(const char *context, const char *timestr,
@@ -262,6 +264,7 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
void *dst = po->flags & (OPT_OFFSET | OPT_SPEC) ?
(uint8_t *)optctx + po->u.off : po->u.dst_ptr;
int *dstcount;
+ double num;
int ret;
if (po->flags & OPT_SPEC) {
@@ -289,15 +292,31 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
return AVERROR(ENOMEM);
*(char **)dst = str;
} else if (po->flags & OPT_BOOL || po->flags & OPT_INT) {
- *(int *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
+ ret = parse_number(opt, arg, OPT_INT64, INT_MIN, INT_MAX, &num);
+ if (ret < 0)
+ return ret;
+
+ *(int *)dst = num;
} else if (po->flags & OPT_INT64) {
- *(int64_t *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX);
+ ret = parse_number(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX, &num);
+ if (ret < 0)
+ return ret;
+
+ *(int64_t *)dst = num;
} else if (po->flags & OPT_TIME) {
*(int64_t *)dst = parse_time_or_die(opt, arg, 1);
} else if (po->flags & OPT_FLOAT) {
- *(float *)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
+ ret = parse_number(opt, arg, OPT_FLOAT, -INFINITY, INFINITY, &num);
+ if (ret < 0)
+ return ret;
+
+ *(float *)dst = num;
} else if (po->flags & OPT_DOUBLE) {
- *(double *)dst = parse_number_or_die(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY);
+ ret = parse_number(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY, &num);
+ if (ret < 0)
+ return ret;
+
+ *(double *)dst = num;
} else if (po->u.func_arg) {
int ret = po->u.func_arg(optctx, opt, arg);
if (ret < 0) {