int gb2Utf8(const char* source, int sourceLen, void *target, int targetLen)
{
int result = 0;
int bufLen = strlen(source) * 2;
wchar_t *buffer = (wchar_t *)malloc(bufLen);
if (!buffer)
{
result = 1;
goto RETURN;
}
//GB18030 code page: 54936
int m2wResult = MultiByteToWideChar(54936, MB_ERR_INVALID_CHARS, source, -1, buffer, bufLen);
if (!m2wResult)
{
result = 2;
goto RETURN;
}
int w2mResult = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, buffer, -1, (char *)target, targetLen, NULL, NULL);
if (!w2mResult)
{
result = 3;
goto RETURN;
}
RETURN:
free(buffer);
return result;
}
當程序運行到free(buffer)
時,它會崩潰,但我不知道爲什麼。
如果將bufLen
修改爲一個常數值,或者刪除MultiByteToWideChar
函數,它不會崩潰,我也不知道爲什麼。 這是當碰撞調用堆棧:!爲什麼此功能在空閒內存時總是崩潰?
msvcr100d.dll _free_dbg_nolock(void *的pUserData,詮釋nBlockUse)線1376 + 0x3b字節C++
msvcr100d.dll _free_dbg(void *的pUserData,詮釋nBlockUse)線1265 + 0xd bytes C++
msvcr100d.dll!free(void * pUserData)line 49 + 0xb bytes C++
New.exe!gb2Utf8(const char * source,int sourceLen,void * target,int targetLen)Line 156 + 0xc字節C++
New.exe!wWinMain(HINSTANCE__ * hInstance,HINSTANCE__ * hPrevInstance,wchar_t * lpCmdLine,int nCmdShow)第29行+ 0x11字節C++
N ew.exe!__ tmainCRTStartup()線547 + 0x2c上字節Ç
New.exe!wWinMainCRTStartup()線371℃
KERNEL32.DLL!7509339a()下面
[幀可以是不正確的和/或缺失,無符號加載爲KERNEL32.DLL]
NTDLL.DLL!77979ef2()
NTDLL.DLL!77979ec5()
坦克大家都在尋求幫助,這個函數有兩個錯誤。 – user805627 2012-07-19 05:10:52