Commit 346168e0 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

- Save one malloc()

- Return NULL in case of error
parent 6eba55d5
...@@ -140,18 +140,18 @@ static char *MB2MB( const char *string, UINT fromCP, UINT toCP ) ...@@ -140,18 +140,18 @@ static char *MB2MB( const char *string, UINT fromCP, UINT toCP )
int len; int len;
len = MultiByteToWideChar( fromCP, 0, string, -1, NULL, 0 ); len = MultiByteToWideChar( fromCP, 0, string, -1, NULL, 0 );
assert( len > 0 ); if( len == 0 );
wide = (wchar_t *)malloc (len * sizeof (wchar_t));
if( wide == NULL )
return NULL; return NULL;
wchar_t wide[len];
MultiByteToWideChar( fromCP, 0, string, -1, wide, len ); MultiByteToWideChar( fromCP, 0, string, -1, wide, len );
len = WideCharToMultiByte( toCP, 0, wide, -1, NULL, 0, NULL, NULL ); len = WideCharToMultiByte( toCP, 0, wide, -1, NULL, 0, NULL, NULL );
assert( len > 0 ); if( len == 0 )
return NULL;
out = malloc( len ); out = malloc( len );
WideCharToMultiByte( toCP, 0, wide, -1, out, len, NULL, NULL ); WideCharToMultiByte( toCP, 0, wide, -1, out, len, NULL, NULL );
free( wide );
return out; return out;
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment