1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-28 02:23:06 +00:00

bstr: don't abort on format error in bstr_xappend_vasprintf

Most of the time it is recoverable error, and it makes no sense to
abort here.
This commit is contained in:
Kacper Michajłow 2024-09-25 02:00:03 +02:00 committed by sfan5
parent 2c2755992d
commit 96006fa97b
2 changed files with 9 additions and 7 deletions

View File

@ -376,17 +376,18 @@ void bstr_xappend(void *talloc_ctx, bstr *s, bstr append)
s->start[s->len] = '\0';
}
void bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...)
int bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
bstr_xappend_vasprintf(talloc_ctx, s, fmt, ap);
int ret = bstr_xappend_vasprintf(talloc_ctx, s, fmt, ap);
va_end(ap);
return ret;
}
// Exactly as bstr_xappend(), but with a formatted string.
void bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt,
va_list ap)
int bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt,
va_list ap)
{
int size;
va_list copy;
@ -397,13 +398,14 @@ void bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt,
va_end(copy);
if (size < 0)
abort();
return size;
if (avail < 1 || size + 1 > avail) {
resize_append(talloc_ctx, s, size + 1);
vsnprintf(s->start + s->len, size + 1, fmt, ap);
}
s->len += size;
return size;
}
bool bstr_case_startswith(struct bstr s, struct bstr prefix)

View File

@ -136,9 +136,9 @@ static inline struct bstr bstr_getline(struct bstr str, struct bstr *rest)
struct bstr bstr_strip_linebreaks(struct bstr str);
void bstr_xappend(void *talloc_ctx, bstr *s, bstr append);
void bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...)
int bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...)
PRINTF_ATTRIBUTE(3, 4);
void bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt, va_list va)
int bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt, va_list va)
PRINTF_ATTRIBUTE(3, 0);
// If s starts/ends with prefix, return true and return the rest of the string