mirror of
https://github.com/mpv-player/mpv
synced 2024-12-22 23:02:37 +00:00
options: fix specifying string options without parameter
Specifying a string option with no parameter, as in "--dumpfile" with no '=', erroneously set the corresponding variable to NULL. Fix this to give an error about missing parameter instead. Suboption parsing explicitly treated empty option values as if the option had been specified with no value (no '='). Thus it was not possible to specify empty strings as values. I think this behavior was originally added only because of other limitations in the old implementation. Remove it, so that suboptions now behave the same as top-level ones in this regard. Document the NULL-distinguishing property of bstrdup0() that the code depends on, and also make bstrdup() behave consistently.
This commit is contained in:
parent
9426c5f92a
commit
86571435ba
6
bstr.h
6
bstr.h
@ -36,14 +36,18 @@ struct bstr {
|
||||
|
||||
// demux_rtp.cpp (live555) C++ compilation workaround
|
||||
#ifndef __cplusplus
|
||||
// If str.start is NULL, return NULL.
|
||||
static inline char *bstrdup0(void *talloc_ctx, struct bstr str)
|
||||
{
|
||||
return talloc_strndup(talloc_ctx, (char *)str.start, str.len);
|
||||
}
|
||||
|
||||
// Return start = NULL iff that is true for the original.
|
||||
static inline struct bstr bstrdup(void *talloc_ctx, struct bstr str)
|
||||
{
|
||||
struct bstr r = { talloc_strndup(talloc_ctx, str.start, str.len), str.len };
|
||||
struct bstr r = { NULL, str.len };
|
||||
if (str.start)
|
||||
r.start = talloc_memdup(talloc_ctx, str.start, str.len);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -458,6 +458,9 @@ static int parse_str(const m_option_t *opt, struct bstr name,
|
||||
struct bstr param, bool ambiguous_param, void *dst,
|
||||
void *talloc_ctx)
|
||||
{
|
||||
if (param.start == NULL)
|
||||
return M_OPT_MISSING_PARAM;
|
||||
|
||||
if ((opt->flags & M_OPT_MIN) && (param.len < opt->min)) {
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"Parameter must be >= %d chars: %.*s\n",
|
||||
@ -891,8 +894,7 @@ static int parse_subconf(const m_option_t *opt, struct bstr name,
|
||||
if (dst) {
|
||||
lst = talloc_realloc(NULL, lst, char *, 2 * (nr + 2));
|
||||
lst[2 * nr] = bstrdup0(lst, subopt);
|
||||
lst[2 * nr + 1] = subparam.len == 0 ? NULL :
|
||||
bstrdup0(lst, subparam);
|
||||
lst[2 * nr + 1] = bstrdup0(lst, subparam);
|
||||
memset(&lst[2 * (nr + 1)], 0, 2 * sizeof(char *));
|
||||
nr++;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user