From 48d529f714e51b0117c1b5592719578848672d4b Mon Sep 17 00:00:00 2001
From: BogDan Vatra <bogdan@kde.org>
Date: Tue, 13 Jan 2015 18:57:18 +0200
Subject: [PATCH 1/2] Fix crappy vswprintf implemenation on Android.
It was the main reason for most of the crashes (e.g. sound).
---
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 849c76e..6b7be9a 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 | std::wstring ret(fmt); |
| 138 | boost::algorithm::replace_all(ret, L"%ls", L"%S"); |
| 139 | boost::algorithm::replace_all(ret, L"%hs", L"%s"); |
| 140 | return std::move(ret); |
| 141 | } |
| 142 | #endif |
130 | 143 | |
131 | 144 | // copy at most <max_src_chars> (not including trailing null) from |
132 | 145 | // <src> into <dst>, which must not overlap. |
… |
… |
int tvsprintf_s(tchar* dst, size_t max_dst_chars, const tchar* fmt, va_list ap)
|
236 | 249 | return -1; |
237 | 250 | } |
238 | 251 | |
| 252 | #if OS_ANDROID |
| 253 | memset(dst, 0, max_dst_chars * sizeof(tchar)); |
| 254 | const int ret = tvsnprintf(dst, max_dst_chars, androidFormat(fmt).c_str(), ap); |
| 255 | #else |
239 | 256 | const int ret = tvsnprintf(dst, max_dst_chars, fmt, ap); |
| 257 | #endif |
240 | 258 | if(ret >= int(max_dst_chars)) // not enough space |
241 | 259 | { |
242 | 260 | dst[0] = '\0'; |