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
--- a/ucx/utils.c	Wed Aug 14 15:24:14 2013 +0200
+++ b/ucx/utils.c	Wed Aug 14 15:54:22 2013 +0200
@@ -147,6 +147,8 @@
 
 int ucx_vfprintf(void *stream, write_func wfc, const char *fmt, va_list ap) {
     char buf[UCX_PRINTF_BUFSIZE];
+    va_list ap2;
+    va_copy(ap2, ap);
     int ret = vsnprintf(buf, UCX_PRINTF_BUFSIZE, fmt, ap);
     if (ret < 0) {
         return ret;
@@ -164,7 +166,8 @@
             return -1;
         }
         
-        ret = vsnprintf(newbuf, len, fmt, ap);
+        ret = vsnprintf(newbuf, len, fmt, ap2);
+        va_end(ap2);
         if (ret > 0) {
             ret = (int)wfc(newbuf, 1, ret, stream);
         }
@@ -186,6 +189,8 @@
     sstr_t s;
     s.ptr = NULL;
     s.length = 0;
+    va_list ap2;
+    va_copy(ap2, ap);
     char buf[UCX_PRINTF_BUFSIZE];
     int ret = vsnprintf(buf, UCX_PRINTF_BUFSIZE, fmt, ap);
     if (ret > 0 && ret < UCX_PRINTF_BUFSIZE) {
@@ -198,7 +203,8 @@
     } else  {
         int len = ret + 1;
         s.ptr = (char*)a->malloc(a->pool, len);
-        ret = vsnprintf(s.ptr, len, fmt, ap);
+        ret = vsnprintf(s.ptr, len, fmt, ap2);
+        va_end(ap2);
         if (ret < 0) {
             free(s.ptr);
             s.ptr = NULL;
--- a/ucx/utils.h	Wed Aug 14 15:24:14 2013 +0200
+++ b/ucx/utils.h	Wed Aug 14 15:54:22 2013 +0200
@@ -202,7 +202,7 @@
 int ucx_vfprintf(void *stream, write_func wfc, const char *fmt, va_list ap);
 
 /**
- * A printf lile function which stores the result in a newly created string.
+ * A printf like function which stores the result in a newly created string.
  * 
  * The sstr_t data is allocated with the allocators ucx_allocator_malloc
  * function. So it is implementation depended, whether the returned

mercurial