diff --git a/misc/bstr.c b/misc/bstr.c index 4a8bf16ac1..120abef8fe 100644 --- a/misc/bstr.c +++ b/misc/bstr.c @@ -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) diff --git a/misc/bstr.h b/misc/bstr.h index 5cc124ec36..d279a3a088 100644 --- a/misc/bstr.h +++ b/misc/bstr.h @@ -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