From 2cc956ddb59c1e12a0a1aac481d2a99d6437d9d6 Mon Sep 17 00:00:00 2001
From: BogDan Vatra <bogdan@kde.org>
Date: Wed, 14 Jan 2015 09:46:59 +0200
Subject: [PATCH] Fix crappy vswprintf implemenation on Android.
It was the main reason for most of the crashes (e.g. sound).
---
source/lib/secure_crt.cpp | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/source/lib/secure_crt.cpp b/source/lib/secure_crt.cpp
index 849c76e..b412758 100644
a
|
b
|
|
32 | 32 | |
33 | 33 | #include "lib/secure_crt.h" |
34 | 34 | |
| 35 | #if OS_ANDROID |
| 36 | # include <boost/algorithm/string/replace.hpp> |
| 37 | #endif |
| 38 | |
35 | 39 | // we were included from wsecure_crt.cpp; skip all stuff that |
36 | 40 | // must only be done once. |
37 | 41 | #ifndef WSECURE_CRT |
… |
… |
size_t tnlen(const tchar* str, size_t max_len)
|
127 | 131 | } |
128 | 132 | #endif // !OS_UNIX |
129 | 133 | |
| 134 | #if OS_ANDROID |
| 135 | static std::wstring androidFormat(const tchar *fmt) |
| 136 | { |
| 137 | // FIXME handle %%hs, %%ls |
| 138 | std::wstring ret(fmt); |
| 139 | boost::algorithm::replace_all(ret, L"%ls", L"%S"); |
| 140 | boost::algorithm::replace_all(ret, L"%.*ls", L"%.*S"); |
| 141 | boost::algorithm::replace_all(ret, L"%hs", L"%s"); |
| 142 | boost::algorithm::replace_all(ret, L"%.*hs", L"%.*s"); |
| 143 | return std::move(ret); |
| 144 | } |
| 145 | #endif |
130 | 146 | |
131 | 147 | // copy at most <max_src_chars> (not including trailing null) from |
132 | 148 | // <src> into <dst>, which must not overlap. |
… |
… |
int tvsprintf_s(tchar* dst, size_t max_dst_chars, const tchar* fmt, va_list ap)
|
236 | 252 | return -1; |
237 | 253 | } |
238 | 254 | |
| 255 | #if OS_ANDROID |
| 256 | memset(dst, 0, max_dst_chars * sizeof(tchar)); |
| 257 | const int ret = tvsnprintf(dst, max_dst_chars, androidFormat(fmt).c_str(), ap); |
| 258 | #else |
239 | 259 | const int ret = tvsnprintf(dst, max_dst_chars, fmt, ap); |
| 260 | #endif |
240 | 261 | if(ret >= int(max_dst_chars)) // not enough space |
241 | 262 | { |
242 | 263 | dst[0] = '\0'; |