Skip to content

Commit c9d1ee7

Browse files
committed
Merge branch 'rs/vsnprintf-failure-is-not-a-bug'
Demote a BUG() to an die() when the failure from vsnprintf() may not be due to a programmer error. * rs/vsnprintf-failure-is-not-a-bug: don't report vsnprintf(3) error as bug
2 parents 9f32d8d + 0283cd5 commit c9d1ee7

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

mem-pool.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "git-compat-util.h"
66
#include "mem-pool.h"
7+
#include "gettext.h"
78

89
#define BLOCK_GROWTH_SIZE (1024 * 1024 - sizeof(struct mp_block))
910

@@ -122,7 +123,7 @@ static char *mem_pool_strvfmt(struct mem_pool *pool, const char *fmt,
122123
len = vsnprintf(next_free, available, fmt, cp);
123124
va_end(cp);
124125
if (len < 0)
125-
BUG("your vsnprintf is broken (returned %d)", len);
126+
die(_("unable to format message: %s"), fmt);
126127

127128
size = st_add(len, 1); /* 1 for NUL */
128129
ret = mem_pool_alloc(pool, size);

strbuf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void strbuf_vinsertf(struct strbuf *sb, size_t pos, const char *fmt, va_list ap)
277277
len = vsnprintf(sb->buf + sb->len, 0, fmt, cp);
278278
va_end(cp);
279279
if (len < 0)
280-
BUG("your vsnprintf is broken (returned %d)", len);
280+
die(_("unable to format message: %s"), fmt);
281281
if (!len)
282282
return; /* nothing to do */
283283
if (unsigned_add_overflows(sb->len, len))
@@ -404,7 +404,7 @@ void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap)
404404
len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, cp);
405405
va_end(cp);
406406
if (len < 0)
407-
BUG("your vsnprintf is broken (returned %d)", len);
407+
die(_("unable to format message: %s"), fmt);
408408
if (len > strbuf_avail(sb)) {
409409
strbuf_grow(sb, len);
410410
len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);

wrapper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ int xsnprintf(char *dst, size_t max, const char *fmt, ...)
670670
va_end(ap);
671671

672672
if (len < 0)
673-
BUG("your snprintf is broken");
673+
die(_("unable to format message: %s"), fmt);
674674
if (len >= max)
675675
BUG("attempt to snprintf into too-small buffer");
676676
return len;

0 commit comments

Comments
 (0)