summaryrefslogtreecommitdiffstats
path: root/misc/bstr.h
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2024-04-08 01:28:14 +0200
committerKacper Michajłow <kasper93@gmail.com>2024-04-08 02:06:06 +0200
commitd3941f235a73f0eb881919bafe208f63ad6a33d5 (patch)
treea03eecd4e7e3b33224824f6e3b4caecfdad51d2c /misc/bstr.h
parent2d4fae4f706c5c400acbc8a27d7819b4d539a315 (diff)
downloadmpv-d3941f235a73f0eb881919bafe208f63ad6a33d5.tar.bz2
mpv-d3941f235a73f0eb881919bafe208f63ad6a33d5.tar.xz
bstr: change bstr0_s to bstr0_lit, restrict it only for string literals
Allows to avoid non-portable strlen usage. Also avoid "initializer element is not constant" warnings on older GCC that doesn't like explicit type specification in aggregate initialization. Co-authored-by: NRK <nrk@disroot.org> Co-authored-by: nanahi <130121847+na-na-hi@users.noreply.github.com>
Diffstat (limited to 'misc/bstr.h')
-rw-r--r--misc/bstr.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/misc/bstr.h b/misc/bstr.h
index 482faa661e..aaae7d695c 100644
--- a/misc/bstr.h
+++ b/misc/bstr.h
@@ -56,11 +56,11 @@ static inline struct bstr bstrdup(void *talloc_ctx, struct bstr str)
return r;
}
-#define bstr0_s(s) (struct bstr){(unsigned char *)(s), (s) ? strlen(s) : 0}
+#define bstr0_lit(s) {(unsigned char *)(s), sizeof("" s) - 1}
static inline struct bstr bstr0(const char *s)
{
- return bstr0_s(s);
+ return (struct bstr){(unsigned char *)s, s ? strlen(s) : 0};
}
int bstrcmp(struct bstr str1, struct bstr str2);