From: Andrii Simiklit <andrii.simik...@globallogic.com>

MSDN:
"va_end must be called on each argument list that's initialized
 with va_start or va_copy before the function returns."

v2: Linux man about vXXXprintf functions:
    "These functions do not call the va_end macro. Because they
     invoke the va_arg  macro, the value of ap is undefined after the call"
    So we should have instance copy of va_list for each 'vXXXprintf' call.

v3: Fixed case when malloc returns 0 in util_vasprintf

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107810
Signed-off-by: Andrii Simiklit <andrii.simik...@globallogic.com>
---
 src/util/u_string.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/util/u_string.h b/src/util/u_string.h
index ce45430..e408146 100644
--- a/src/util/u_string.h
+++ b/src/util/u_string.h
@@ -81,6 +81,7 @@ util_vsnprintf(char *str, size_t size, const char *format, 
va_list ap)
    if (ret < 0) {
       ret = _vscprintf(format, ap_copy);
    }
+   va_end(ap_copy);
    return ret;
 }
 
@@ -119,14 +120,14 @@ util_vasprintf(char **ret, const char *format, va_list ap)
 
    /* Compute length of output string first */
    va_copy(ap_copy, ap);
-   int r = util_vsnprintf(NULL, 0, format, ap);
+   int r = util_vsnprintf(NULL, 0, format, ap_copy);
    va_end(ap_copy);
 
    if (r < 0)
       return -1;
 
    *ret = (char *) malloc(r + 1);
-   if (!ret)
+   if (!*ret)
       return -1;
 
    /* Print to buffer */
-- 
2.7.4

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to