fixed printf functions

Wed, 14 Aug 2013 15:54:22 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 14 Aug 2013 15:54:22 +0200
changeset 144
b6dcc9d112eb
parent 143
b843d463ac58
child 145
e974640ec4e0

fixed printf functions

ucx/utils.c file | annotate | diff | comparison | revisions
ucx/utils.h file | annotate | diff | comparison | revisions
     1.1 --- a/ucx/utils.c	Wed Aug 14 15:24:14 2013 +0200
     1.2 +++ b/ucx/utils.c	Wed Aug 14 15:54:22 2013 +0200
     1.3 @@ -147,6 +147,8 @@
     1.4  
     1.5  int ucx_vfprintf(void *stream, write_func wfc, const char *fmt, va_list ap) {
     1.6      char buf[UCX_PRINTF_BUFSIZE];
     1.7 +    va_list ap2;
     1.8 +    va_copy(ap2, ap);
     1.9      int ret = vsnprintf(buf, UCX_PRINTF_BUFSIZE, fmt, ap);
    1.10      if (ret < 0) {
    1.11          return ret;
    1.12 @@ -164,7 +166,8 @@
    1.13              return -1;
    1.14          }
    1.15          
    1.16 -        ret = vsnprintf(newbuf, len, fmt, ap);
    1.17 +        ret = vsnprintf(newbuf, len, fmt, ap2);
    1.18 +        va_end(ap2);
    1.19          if (ret > 0) {
    1.20              ret = (int)wfc(newbuf, 1, ret, stream);
    1.21          }
    1.22 @@ -186,6 +189,8 @@
    1.23      sstr_t s;
    1.24      s.ptr = NULL;
    1.25      s.length = 0;
    1.26 +    va_list ap2;
    1.27 +    va_copy(ap2, ap);
    1.28      char buf[UCX_PRINTF_BUFSIZE];
    1.29      int ret = vsnprintf(buf, UCX_PRINTF_BUFSIZE, fmt, ap);
    1.30      if (ret > 0 && ret < UCX_PRINTF_BUFSIZE) {
    1.31 @@ -198,7 +203,8 @@
    1.32      } else  {
    1.33          int len = ret + 1;
    1.34          s.ptr = (char*)a->malloc(a->pool, len);
    1.35 -        ret = vsnprintf(s.ptr, len, fmt, ap);
    1.36 +        ret = vsnprintf(s.ptr, len, fmt, ap2);
    1.37 +        va_end(ap2);
    1.38          if (ret < 0) {
    1.39              free(s.ptr);
    1.40              s.ptr = NULL;
     2.1 --- a/ucx/utils.h	Wed Aug 14 15:24:14 2013 +0200
     2.2 +++ b/ucx/utils.h	Wed Aug 14 15:54:22 2013 +0200
     2.3 @@ -202,7 +202,7 @@
     2.4  int ucx_vfprintf(void *stream, write_func wfc, const char *fmt, va_list ap);
     2.5  
     2.6  /**
     2.7 - * A printf lile function which stores the result in a newly created string.
     2.8 + * A printf like function which stores the result in a newly created string.
     2.9   * 
    2.10   * The sstr_t data is allocated with the allocators ucx_allocator_malloc
    2.11   * function. So it is implementation depended, whether the returned

mercurial