summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-08-17 21:44:05 +0200
committerwm4 <wm4@nowhere>2016-08-17 21:44:05 +0200
commit3a7e86ff6efc834281d3f112b05a82fc6b2e1023 (patch)
tree029fb05fffec59510996aa192f9bba9bc96c8929
parent12e251c29e1be905ab35c4caed9a6d926c1825b0 (diff)
downloadmpv-3a7e86ff6efc834281d3f112b05a82fc6b2e1023.tar.bz2
mpv-3a7e86ff6efc834281d3f112b05a82fc6b2e1023.tar.xz
m_option: simplify float value range handling
Use clamp_double() to handle all value restriction/verification. The error messages become a bit less nice, but they were kind of incomplete before.
-rw-r--r--options/m_option.c24
1 files changed, 3 insertions, 21 deletions
diff --git a/options/m_option.c b/options/m_option.c
index fd1e6770ee..4dedfe476e 100644
--- a/options/m_option.c
+++ b/options/m_option.c
@@ -921,22 +921,8 @@ static int parse_double(struct mp_log *log, const m_option_t *opt,
return M_OPT_INVALID;
}
- if (opt->flags & M_OPT_MIN)
- if (tmp_float < opt->min) {
- mp_err(log, "The %.*s option must be >= %f: %.*s\n",
- BSTR_P(name), opt->min, BSTR_P(param));
- return M_OPT_OUT_OF_RANGE;
- }
-
- if (opt->flags & M_OPT_MAX)
- if (tmp_float > opt->max) {
- mp_err(log, "The %.*s option must be <= %f: %.*s\n",
- BSTR_P(name), opt->max, BSTR_P(param));
- return M_OPT_OUT_OF_RANGE;
- }
-
- if (!isfinite(tmp_float)) {
- mp_err(log, "The %.*s option must be a finite number: %.*s\n",
+ if (clamp_double(opt, &tmp_float) < 0) {
+ mp_err(log, "The %.*s option is out of range: %.*s\n",
BSTR_P(name), BSTR_P(param));
return M_OPT_OUT_OF_RANGE;
}
@@ -990,11 +976,7 @@ static int double_set(const m_option_t *opt, void *dst, struct mpv_node *src)
} else {
return M_OPT_UNKNOWN;
}
- if ((opt->flags & M_OPT_MIN) && val < opt->min)
- return M_OPT_OUT_OF_RANGE;
- if ((opt->flags & M_OPT_MAX) && val > opt->max)
- return M_OPT_OUT_OF_RANGE;
- if (!isfinite(val))
+ if (clamp_double(opt, &val) < 0)
return M_OPT_OUT_OF_RANGE;
*(double *)dst = val;
return 1;