History

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.

Kacper Michajłow committed 2 years ago

Commit 96006fa1 parent 2c275592 files · +9 −7Browse files

Unified · Split

2 files
  1. misc/bstr.c +7 −5
  2. misc/bstr.h +2 −2
misc/bstr.c+7−5
@@ -376,17 +376,18 @@ void bstr_xappend(void *talloc_ctx, bstr *s, bstr append) · 375 unmodified lines
376376 s->start[s->len] = '\0';
377377 }
378378
379−void bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...)
379+int bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...)
380380 {
381381 va_list ap;
382382 va_start(ap, fmt);
383− bstr_xappend_vasprintf(talloc_ctx, s, fmt, ap);
383+ int ret = bstr_xappend_vasprintf(talloc_ctx, s, fmt, ap);
384384 va_end(ap);
385+ return ret;
385386 }
386387
387388 // Exactly as bstr_xappend(), but with a formatted string.
388−void bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt,
389− va_list ap)
389+int bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt,
390+ va_list ap)
390391 {
391392 int size;
392393 va_list copy;
@@ -397,13 +398,14 @@ void bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt, · 4 unmodified lines
397398 va_end(copy);
398399
399400 if (size < 0)
400− abort();
401+ return size;
401402
402403 if (avail < 1 || size + 1 > avail) {
403404 resize_append(talloc_ctx, s, size + 1);
404405 vsnprintf(s->start + s->len, size + 1, fmt, ap);
405406 }
406407 s->len += size;
408+ return size;
407409 }
408410
409411 bool bstr_case_startswith(struct bstr s, struct bstr prefix)
misc/bstr.h+2−2
@@ -136,9 +136,9 @@ static inline struct bstr bstr_getline(struct bstr str, struct bstr *rest) · 135 unmodified lines
136136 struct bstr bstr_strip_linebreaks(struct bstr str);
137137
138138 void bstr_xappend(void *talloc_ctx, bstr *s, bstr append);
139−void bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...)
139+int bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...)
140140 PRINTF_ATTRIBUTE(3, 4);
141−void bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt, va_list va)
141+int bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt, va_list va)
142142 PRINTF_ATTRIBUTE(3, 0);
143143
144144 // If s starts/ends with prefix, return true and return the rest of the string

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t