Skip to content
Snippets Groups Projects
Commit dad68c33 authored by James Johnston's avatar James Johnston Committed by Brad King
Browse files

Encoding: Fix undefined behavior if out of memory.

Change-Id: Id632329f3593da977ce52de42ad39af4e6fb01dd
parent 4db8e69f
No related branches found
No related tags found
No related merge requests found
......@@ -45,8 +45,11 @@ wchar_t* kwsysEncoding_DupToWide(const char* str)
if(length > 0)
{
ret = (wchar_t*)malloc((length)*sizeof(wchar_t));
ret[0] = 0;
kwsysEncoding_mbstowcs(ret, str, length);
if(ret)
{
ret[0] = 0;
kwsysEncoding_mbstowcs(ret, str, length);
}
}
return ret;
}
......@@ -72,8 +75,11 @@ char* kwsysEncoding_DupToNarrow(const wchar_t* str)
if(length > 0)
{
ret = (char*)malloc(length);
ret[0] = 0;
kwsysEncoding_wcstombs(ret, str, length);
if(ret)
{
ret[0] = 0;
kwsysEncoding_wcstombs(ret, str, length);
}
}
return ret;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment