From ad3e330861ee924e9accdd20320c035a8cbe2c33 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Fri, 23 Jan 2015 20:38:13 +0000 Subject: [PATCH] Workaround for limitations of Android's vswprintf implementation. Based on patch by BogDan. Refs #2996. This was SVN commit r16203. --- source/lib/secure_crt.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/source/lib/secure_crt.cpp b/source/lib/secure_crt.cpp index 40c077187c..02055e866d 100644 --- a/source/lib/secure_crt.cpp +++ b/source/lib/secure_crt.cpp @@ -32,6 +32,10 @@ #include "lib/secure_crt.h" +#if OS_ANDROID +# include +#endif + // we were included from wsecure_crt.cpp; skip all stuff that // must only be done once. #ifndef WSECURE_CRT @@ -127,6 +131,16 @@ size_t tnlen(const tchar* str, size_t max_len) } #endif // !OS_UNIX +#if OS_ANDROID +static std::wstring androidFormat(const tchar *fmt) +{ + // FIXME handle %%hs, %%ls, etc + std::wstring ret(fmt); + boost::algorithm::replace_all(ret, L"%ls", L"%S"); + boost::algorithm::replace_all(ret, L"%hs", L"%s"); + return ret; +} +#endif // copy at most (not including trailing null) from // into , which must not overlap. @@ -236,7 +250,11 @@ int tvsprintf_s(tchar* dst, size_t max_dst_chars, const tchar* fmt, va_list ap) return -1; } +#if OS_ANDROID + const int ret = tvsnprintf(dst, max_dst_chars, androidFormat(fmt).c_str(), ap); +#else const int ret = tvsnprintf(dst, max_dst_chars, fmt, ap); +#endif if(ret < 0 || ret >= int(max_dst_chars)) // not enough space { dst[0] = '\0';