From: Martin Willi Date: Fri, 13 Jul 2012 10:12:24 +0000 (+0200) Subject: Append directly to base string in vstr printf hooks X-Git-Tag: 5.0.1~388 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=060555f082d84a605ecf8e5ab19a7c782eb4b818;p=thirdparty%2Fstrongswan.git Append directly to base string in vstr printf hooks --- diff --git a/src/libstrongswan/printf_hook.c b/src/libstrongswan/printf_hook.c index 22f5d78d9d..2ae8043801 100644 --- a/src/libstrongswan/printf_hook.c +++ b/src/libstrongswan/printf_hook.c @@ -141,14 +141,13 @@ static int custom_arginfo(const struct printf_info *info, size_t n, int *argtype */ static int custom_fmt_cb(Vstr_base *base, size_t pos, Vstr_fmt_spec *fmt_spec) { - int i, written; - char buf[PRINTF_BUF_LEN]; + int i; const void *args[ARGS_MAX]; printf_hook_spec_t spec; printf_hook_handler_t *handler = printf_hooks[SPEC_TO_INDEX(fmt_spec->name[0])]; printf_hook_data_t data = { - .buf = buf, - .buflen = sizeof(buf), + .base = base, + .pos = pos, }; for (i = 0; i < handler->numargs; i++) @@ -168,11 +167,7 @@ static int custom_fmt_cb(Vstr_base *base, size_t pos, Vstr_fmt_spec *fmt_spec) spec.minus = fmt_spec->fmt_minus; spec.width = fmt_spec->fmt_field_width; - written = handler->hook(&data, &spec, args); - if (written > 0) - { - vstr_add_buf(base, pos, buf, written); - } + handler->hook(&data, &spec, args); return 1; } diff --git a/src/libstrongswan/printf_hook.h b/src/libstrongswan/printf_hook.h index fa11b6f9b9..93026cc34e 100644 --- a/src/libstrongswan/printf_hook.h +++ b/src/libstrongswan/printf_hook.h @@ -115,27 +115,22 @@ int vstr_wrapper_vasprintf(char **str, const char *format, va_list ap); struct printf_hook_data_t { /** - * Buffer to write to + * Base to append printf to */ - char *buf; + Vstr_base *base; /** - * Size of the buffer + * Position in base to write to */ - size_t buflen; + size_t pos; }; /** * Helper macro to be used in printf hook callbacks. */ #define print_in_hook(data, fmt, ...) ({\ - int _written = snprintf(data->buf, data->buflen, fmt, ##__VA_ARGS__);\ - if (_written < 0 || _written >= data->buflen)\ - {\ - _written = data->buflen - 1;\ - }\ - data->buf += _written;\ - data->buflen -= _written;\ + int _written = vstr_add_fmt(data->base, data->pos, fmt, ##__VA_ARGS__);\ + data->pos += _written;\ _written;\ })