Browse Source

Fix varargs misuse in sbuffer module

master
Damien Goutte-Gattat 11 years ago
parent
commit
fe3e2f0e4d
  1. 13
      lib/sbuffer.c

13
lib/sbuffer.c

@ -45,7 +45,7 @@ struct string_buffer_t
#define GROW(s,l) \
do { \
(s)->size = ((((s)->len + (l)) / (s)->block) + 1) * (s)->block; \
(s)->buffer = xrealloc((s)->buffer, (s)->len); \
(s)->buffer = xrealloc((s)->buffer, (s)->size); \
} while ( 0 )
#else
@ -192,20 +192,19 @@ int
sb_vaddf(string_buffer_t *s, const char *fmt, va_list ap)
{
int written;
va_list aq;
if ( ! s || ! fmt ) {
errno = EINVAL;
return -1;
}
written = vsnprintf(CURSOR(s), AVAILABLE_SIZE(s), fmt, ap);
va_copy(aq, ap);
written = vsnprintf(CURSOR(s), AVAILABLE_SIZE(s), fmt, aq);
va_end(aq);
if ( written >= AVAILABLE_SIZE(s) ) {
va_list aq;
GROW(s, written);
va_copy(aq, ap);
vsprintf(CURSOR(s), fmt, aq);
va_end(aq);
vsprintf(CURSOR(s), fmt, ap);
}
s->len += written;

Loading…
Cancel
Save