You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2018/07/18 15:50:31 UTC

[trafficserver] branch master updated: Fixes some var-args missing va_start/end

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 7acfcfb  Fixes some var-args missing va_start/end
7acfcfb is described below

commit 7acfcfbc69d7ab88517f4090f1d168a960a5d151
Author: Katsutoshi Ikenoya <ki...@yahoo-corp.jp>
AuthorDate: Tue Jul 17 10:52:08 2018 -0400

    Fixes some var-args missing va_start/end
    
    This was introduced in
    
         https://github.com/apache/trafficserver/pull/1299
    
    But, the good news is that this has not been part of a release.
---
 lib/ts/ink_sprintf.cc        |  1 +
 proxy/http/HttpBodyFactory.h | 10 ++++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/ts/ink_sprintf.cc b/lib/ts/ink_sprintf.cc
index 0053384..46db8c3 100644
--- a/lib/ts/ink_sprintf.cc
+++ b/lib/ts/ink_sprintf.cc
@@ -69,6 +69,7 @@ ink_bvsprintf(char *buffer, const char *format, va_list ap)
   const char *s;
   char *d, *p, *s_val, d_buffer[32];
   va_list ap_local;
+
   va_copy(ap_local, ap);
 
   s = format;
diff --git a/proxy/http/HttpBodyFactory.h b/proxy/http/HttpBodyFactory.h
index 2ca8693..19145e9 100644
--- a/proxy/http/HttpBodyFactory.h
+++ b/proxy/http/HttpBodyFactory.h
@@ -162,15 +162,21 @@ public:
   getFormat(int64_t max_buffer_length, int64_t *resulting_buffer_length, const char *format, ...)
   {
     char *msg = nullptr;
-    va_list ap;
     if (format) {
+      va_list ap;
+
+      va_start(ap, format);
+
       // The length from ink_bvsprintf includes the trailing NUL, so adjust the final
-      // length accordingly.
+      // length accordingly. Note that ink_bvsprintf() copies the va_list, so we only
+      // have to set it up once.
       int l = ink_bvsprintf(nullptr, format, ap);
+
       if (l <= max_buffer_length) {
         msg                      = (char *)ats_malloc(l);
         *resulting_buffer_length = ink_bvsprintf(msg, format, ap) - 1;
       }
+      va_end(ap);
     }
     return msg;
   }