summaryrefslogtreecommitdiffstats
path: root/bstr.h
diff options
context:
space:
mode:
authorUoti Urpala <uau@mplayer2.org>2012-06-29 05:14:26 +0300
committerUoti Urpala <uau@mplayer2.org>2012-07-16 21:08:42 +0300
commit86571435baf116a91a31451d26224600f3575270 (patch)
treeaf013eb73a698e577817b806514b20845b8f3602 /bstr.h
parent9426c5f92aab4b561c568e4250f5b250e2aa45c5 (diff)
downloadmpv-86571435baf116a91a31451d26224600f3575270.tar.bz2
mpv-86571435baf116a91a31451d26224600f3575270.tar.xz
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.
Diffstat (limited to 'bstr.h')
-rw-r--r--bstr.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/bstr.h b/bstr.h
index b3f942535e..99b7eea578 100644
--- a/bstr.h
+++ b/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;
}