[v2] mesa/util: add missing va_end() after va_copy()

Submitted by andrey simiklit on Sept. 4, 2018, 12:56 p.m.

Details

Message ID 1536065788-23385-1-git-send-email-asimiklit.work@gmail.com
State New
Headers show
Series "mesa/util: add missing va_end() after va_copy()" ( rev: 2 ) in Mesa

Not browsing as part of any series.

Commit Message

andrey simiklit Sept. 4, 2018, 12:56 p.m.
From: Andrii Simiklit <andrii.simiklit@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.

Signed-off-by: Andrii Simiklit <andrii.simiklit@globallogic.com>
---
 src/util/u_string.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/src/util/u_string.h b/src/util/u_string.h
index ce45430..2bccb10 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,7 +120,7 @@  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)