[libcxx-commits] [PATCH] D97473: [SystemZ][z/OS] vasprintf fix libc++
Muiez Ahmed via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Mar 18 12:01:22 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf6af5efcec41: [SystemZ][z/OS] vasprintf fix libc++ (authored by muiez).
Changed prior to commit:
https://reviews.llvm.org/D97473?vs=329065&id=331647#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D97473/new/
https://reviews.llvm.org/D97473
Files:
libcxx/include/__support/ibm/xlocale.h
libcxx/src/support/win32/support.cpp
Index: libcxx/src/support/win32/support.cpp
===================================================================
--- libcxx/src/support/win32/support.cpp
+++ libcxx/src/support/win32/support.cpp
@@ -22,7 +22,10 @@
{
*sptr = NULL;
// Query the count required.
- int count = _vsnprintf( NULL, 0, format, ap );
+ va_list ap_copy;
+ va_copy(ap_copy, ap);
+ int count = _vsnprintf( NULL, 0, format, ap_copy );
+ va_end(ap_copy);
if (count < 0)
return count;
size_t buffer_size = static_cast<size_t>(count) + 1;
Index: libcxx/include/__support/ibm/xlocale.h
===================================================================
--- libcxx/include/__support/ibm/xlocale.h
+++ libcxx/include/__support/ibm/xlocale.h
@@ -10,6 +10,7 @@
#ifndef _LIBCPP_SUPPORT_IBM_XLOCALE_H
#define _LIBCPP_SUPPORT_IBM_XLOCALE_H
+#include <stdarg.h>
#include <__support/ibm/locale_mgmt_aix.h>
#include <__support/ibm/locale_mgmt_zos.h>
@@ -268,18 +269,19 @@
}
static inline
-int vasprintf(char **strp, const char *fmt, va_list ap)
-{
+int vasprintf(char **strp, const char *fmt, va_list ap) {
const size_t buff_size = 256;
- int str_size;
- if ((*strp = (char *)malloc(buff_size)) == NULL)
- {
+ if ((*strp = (char *)malloc(buff_size)) == NULL) {
return -1;
}
- if ((str_size = vsnprintf(*strp, buff_size, fmt, ap)) >= buff_size)
- {
- if ((*strp = (char *)realloc(*strp, str_size + 1)) == NULL)
- {
+
+ va_list ap_copy;
+ va_copy(ap_copy, ap);
+ int str_size = vsnprintf(*strp, buff_size, fmt, ap_copy);
+ va_end(ap_copy);
+
+ if ((size_t) str_size >= buff_size) {
+ if ((*strp = (char *)realloc(*strp, str_size + 1)) == NULL) {
return -1;
}
str_size = vsnprintf(*strp, str_size + 1, fmt, ap);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97473.331647.patch
Type: text/x-patch
Size: 1773 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210318/abf20ca2/attachment.bin>
More information about the libcxx-commits
mailing list