https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116834
--- Comment #2 from Kacper Michajłow <kasper93 at gmail dot com> --- static inline struct bstr bstr0(const char *s) { return (struct bstr){(unsigned char *)s, s ? strlen(s) : 0}; } void bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt, va_list ap) { int size; va_list copy; va_copy(copy, ap); size_t avail = talloc_get_size(s->start) - s->len; char *dest = s->start ? s->start + s->len : NULL; size = vsnprintf(dest, avail, fmt, copy); va_end(copy); if (size < 0) { bstr_xappend(talloc_ctx, s, bstr0("format error: ")); bstr_xappend(talloc_ctx, s, bstr0(fmt)); return; } 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; } If you want whole thing https://github.com/mpv-player/mpv/blob/ad7012284eaaaf2064e52668d9243465f5188dd2/misc/bstr.c