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
376 s->start[s->len] = '\0';376 s->start[s->len] = '\0';
377}377}
378 378
379void bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...)379int bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...)
380{380{
381 va_list ap;381 va_list ap;
382 va_start(ap, fmt);382 va_start(ap, fmt);
383 bstr_xappend_vasprintf(talloc_ctx, s, fmt, ap);383 int ret = bstr_xappend_vasprintf(talloc_ctx, s, fmt, ap);
384 va_end(ap);384 va_end(ap);
385 return ret;
385}386}
386 387
387// Exactly as bstr_xappend(), but with a formatted string.388// Exactly as bstr_xappend(), but with a formatted string.
388void bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt,389int bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt,
389 va_list ap)390 va_list ap)
390{391{
391 int size;392 int size;
392 va_list copy;393 va_list copy;
@@ -397,13 +398,14 @@ void bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt, · 4 unmodified lines
397 va_end(copy);398 va_end(copy);
398 399
399 if (size < 0)400 if (size < 0)
400 abort();401 return size;
401 402
402 if (avail < 1 || size + 1 > avail) {403 if (avail < 1 || size + 1 > avail) {
403 resize_append(talloc_ctx, s, size + 1);404 resize_append(talloc_ctx, s, size + 1);
404 vsnprintf(s->start + s->len, size + 1, fmt, ap);405 vsnprintf(s->start + s->len, size + 1, fmt, ap);
405 }406 }
406 s->len += size;407 s->len += size;
408 return size;
407}409}
408 410
409bool bstr_case_startswith(struct bstr s, struct bstr prefix)411bool 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
136struct bstr bstr_strip_linebreaks(struct bstr str);136struct bstr bstr_strip_linebreaks(struct bstr str);
137 137
138void bstr_xappend(void *talloc_ctx, bstr *s, bstr append);138void bstr_xappend(void *talloc_ctx, bstr *s, bstr append);
139void bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...)139int bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...)
140 PRINTF_ATTRIBUTE(3, 4);140 PRINTF_ATTRIBUTE(3, 4);
141void bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt, va_list va)141int bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt, va_list va)
142 PRINTF_ATTRIBUTE(3, 0);142 PRINTF_ATTRIBUTE(3, 0);
143 143
144// If s starts/ends with prefix, return true and return the rest of the string144// 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