mirror of
https://github.com/mpv-player/mpv
synced 2025-01-27 01:53:32 +00:00
m_option: fix braindead --start, --length, --end option parsing bugs
The option type m_option_type_rel_time was completely broken. It interpreted everything starting with a number as percent position. This is because sscanf() semantics are idiotic (trailing string doesn't need to be matched), and due to my own idiocy this was overlooked when testing. Fix by considering sscanf() evil and not using it. (bstr_sscanf() is a straight wrapper around sscanf()). Even if the percent code was fixed, there was another bug: it always interpreted times as negative (starting from end for --start). Fix the basic logic.
This commit is contained in:
parent
af8ded53db
commit
39428525c3
@ -1259,16 +1259,16 @@ static int parse_rel_time(const m_option_t *opt, struct bstr name,
|
||||
return M_OPT_MISSING_PARAM;
|
||||
|
||||
// Percent pos
|
||||
double percent;
|
||||
if (bstr_sscanf(param, "%lf%%", &percent) == 1) {
|
||||
if (percent >= 0 && percent <= 100) {
|
||||
if (bstr_endswith0(param, "%")) {
|
||||
double percent = bstrtod(bstr_splice(param, 0, -1), ¶m);
|
||||
if (param.len == 0 && percent >= 0 && percent <= 100) {
|
||||
t.type = REL_TIME_PERCENT;
|
||||
t.pos = percent;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
double sign = bstr_eatstart0(¶m, "-") ? -1 : +1;
|
||||
bool sign = bstr_eatstart0(¶m, "-");
|
||||
double time;
|
||||
if (parse_timestring(param, &time, 0)) {
|
||||
t.type = sign ? REL_TIME_NEGATIVE : REL_TIME_ABSOLUTE;
|
||||
|
Loading…
Reference in New Issue
Block a user