Ticket #2996: 0006-1-Fix-crappy-vswprintf-implemenation-on-Android.patch

File 0006-1-Fix-crappy-vswprintf-implemenation-on-Android.patch, 1.6 KB (added by BogDan, 9 years ago)
  • source/lib/secure_crt.cpp

    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  
    3232
    3333#include "lib/secure_crt.h"
    3434
     35#if OS_ANDROID
     36# include <boost/algorithm/string/replace.hpp>
     37#endif
     38
    3539// we were included from wsecure_crt.cpp; skip all stuff that
    3640// must only be done once.
    3741#ifndef WSECURE_CRT
    size_t tnlen(const tchar* str, size_t max_len)  
    127131}
    128132#endif // !OS_UNIX
    129133
     134#if OS_ANDROID
     135static 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
    130143
    131144// copy at most <max_src_chars> (not including trailing null) from
    132145// <src> into <dst>, which must not overlap.
    int tvsprintf_s(tchar* dst, size_t max_dst_chars, const tchar* fmt, va_list ap)  
    236249        return -1;
    237250    }
    238251
     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
    239256    const int ret = tvsnprintf(dst, max_dst_chars, fmt, ap);
     257#endif
    240258    if(ret >= int(max_dst_chars))   // not enough space
    241259    {
    242260        dst[0] = '\0';