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/31 20:43:55 UTC
[trafficserver] 07/11: 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 8.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 0815a8578cac438a4b3d9ba1af263c5b35978721
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.
(cherry picked from commit 7acfcfbc69d7ab88517f4090f1d168a960a5d151)
---
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;
}