From 73e5be676384e4743c645ed6d12b8c54df658a4b Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Fri, 24 Mar 2017 10:59:35 +0800 Subject: [PATCH] Fix bugs in UTF8ToGBK and GBKToUTF8 GBK->UTF8 x/2*3 UTF8->GBK x/3*2 --- MiniEngine_Windows.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MiniEngine_Windows.cpp b/MiniEngine_Windows.cpp index 8278dad..b07522e 100644 --- a/MiniEngine_Windows.cpp +++ b/MiniEngine_Windows.cpp @@ -83,7 +83,7 @@ int _UTF8ToGBK(unsigned char * lpUTF8Str,unsigned char * lpGBKStr,int nGBKStrLen string UTF8ToGBK(string UTF8String) { - int sz=UTF8String.size()+32; + int sz=UTF8String.size()*2/3+256; auto utf8str=new unsigned char[sz]; memset(utf8str,0,sz); memcpy(utf8str,UTF8String.c_str(),UTF8String.size()); @@ -102,7 +102,7 @@ string UTF8ToGBK(string UTF8String) string GBKToUTF8(string GBKString) { - int sz=GBKString.size()+32; + int sz=GBKString.size()*3/2+32; auto gbkstr=new unsigned char[sz]; memset(gbkstr,0,sz); memcpy(gbkstr,GBKString.c_str(),GBKString.size());