summaryrefslogtreecommitdiff
path: root/cpp/src/IceUtil/StringUtil.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2016-06-06 14:47:06 -0400
committerBernard Normier <bernard@zeroc.com>2016-06-06 14:47:06 -0400
commit62b4466b0847f9861105ca70791095edf93133d9 (patch)
tree4a135ea1378a96af9850300d982fa8deab4b7df1 /cpp/src/IceUtil/StringUtil.cpp
parentSimplified WindowsStringConverter implementation (diff)
downloadice-62b4466b0847f9861105ca70791095edf93133d9.tar.bz2
ice-62b4466b0847f9861105ca70791095edf93133d9.tar.xz
ice-62b4466b0847f9861105ca70791095edf93133d9.zip
Replaced some ScopeArrays by vector or wstring
Diffstat (limited to 'cpp/src/IceUtil/StringUtil.cpp')
-rw-r--r--cpp/src/IceUtil/StringUtil.cpp26
1 files changed, 6 insertions, 20 deletions
diff --git a/cpp/src/IceUtil/StringUtil.cpp b/cpp/src/IceUtil/StringUtil.cpp
index 1f7b1ea8407..ec33cf8c587 100644
--- a/cpp/src/IceUtil/StringUtil.cpp
+++ b/cpp/src/IceUtil/StringUtil.cpp
@@ -11,10 +11,6 @@
#include <IceUtil/StringConverter.h>
#include <cstring>
-#ifdef ICE_OS_WINRT
-# include <IceUtil/ScopedArray.h>
-#endif
-
using namespace std;
using namespace IceUtil;
@@ -502,9 +498,7 @@ IceUtilInternal::errorToString(int error, LPCVOID source)
{
#ifdef ICE_OS_WINRT
- int size = 256;
- IceUtil::ScopedArray<wchar_t> lpMsgBuf(new wchar_t[size]);
-
+ wstring lpMsgBuf(256, wchar_t());
DWORD stored = 0;
while(stored == 0)
@@ -516,8 +510,8 @@ IceUtilInternal::errorToString(int error, LPCVOID source)
source,
error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- lpMsgBuf.get(),
- size,
+ const_cast<wchar_t*>(lpMsgBuf.data()),
+ static_cast<int>(lpMsgBuf.size()),
NULL);
if(stored == 0)
@@ -525,15 +519,13 @@ IceUtilInternal::errorToString(int error, LPCVOID source)
DWORD err = GetLastError();
if(err == ERROR_INSUFFICIENT_BUFFER)
{
- if(size == 65536)
+ if(lpMsgBuf.size() >= 65536)
{
break; // already at the max size
}
else
{
- size *= 4;
- size = max(size, 65536);
- lpMsgBuf.reset(new wchar_t[size]);
+ lpMsgBuf.resize(min<size_t>(lpMsgBuf.size() * 4, 65536));
}
}
else
@@ -543,7 +535,7 @@ IceUtilInternal::errorToString(int error, LPCVOID source)
}
}
- LPWSTR msg = lpMsgBuf.get();
+ LPWSTR msg = const_cast<wchar_t*>(lpMsgBuf.data());
#else
LPWSTR msg = 0;
@@ -579,12 +571,6 @@ IceUtilInternal::errorToString(int error, LPCVOID source)
}
else
{
-#ifndef ICE_OS_WINRT
- if(msg)
- {
- LocalFree(msg);
- }
-#endif
ostringstream os;
os << "unknown error: " << error;
return os.str();