Skip to content

Commit b560397

Browse files
committed
Resync
1 parent fd934be commit b560397

File tree

1 file changed

+30
-35
lines changed

1 file changed

+30
-35
lines changed

encodings/encoding_utf.c

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,7 @@ bool utf16_to_char_string(const uint16_t *in, char *s, size_t len)
284284
static char *mb_to_mb_string_alloc(const char *str,
285285
enum CodePage cp_in, enum CodePage cp_out)
286286
{
287-
char *path_buf = NULL;
288287
wchar_t *path_buf_wide = NULL;
289-
int path_buf_len = 0;
290288
int path_buf_wide_len = MultiByteToWideChar(cp_in, 0, str, -1, NULL, 0);
291289

292290
/* Windows 95 will return 0 from these functions with
@@ -299,54 +297,51 @@ static char *mb_to_mb_string_alloc(const char *str,
299297
* MultiByteToWideChar also supports CP_UTF7 and CP_UTF8.
300298
*/
301299

302-
if (path_buf_wide_len)
300+
if (!path_buf_wide_len)
301+
return strdup(str);
302+
303+
path_buf_wide = (wchar_t*)
304+
calloc(path_buf_wide_len + sizeof(wchar_t), sizeof(wchar_t));
305+
306+
if (path_buf_wide)
303307
{
304-
path_buf_wide = (wchar_t*)
305-
calloc(path_buf_wide_len + sizeof(wchar_t), sizeof(wchar_t));
308+
MultiByteToWideChar(cp_in, 0,
309+
str, -1, path_buf_wide, path_buf_wide_len);
306310

307-
if (path_buf_wide)
311+
if (*path_buf_wide)
308312
{
309-
MultiByteToWideChar(cp_in, 0,
310-
str, -1, path_buf_wide, path_buf_wide_len);
313+
int path_buf_len = WideCharToMultiByte(cp_out, 0,
314+
path_buf_wide, -1, NULL, 0, NULL, NULL);
311315

312-
if (*path_buf_wide)
316+
if (path_buf_len)
313317
{
314-
path_buf_len = WideCharToMultiByte(cp_out, 0,
315-
path_buf_wide, -1, NULL, 0, NULL, NULL);
318+
char *path_buf = (char*)
319+
calloc(path_buf_len + sizeof(char), sizeof(char));
316320

317-
if (path_buf_len)
321+
if (path_buf)
318322
{
319-
path_buf = (char*)
320-
calloc(path_buf_len + sizeof(char), sizeof(char));
323+
WideCharToMultiByte(cp_out, 0,
324+
path_buf_wide, -1, path_buf,
325+
path_buf_len, NULL, NULL);
321326

322-
if (path_buf)
323-
{
324-
WideCharToMultiByte(cp_out, 0,
325-
path_buf_wide, -1, path_buf,
326-
path_buf_len, NULL, NULL);
327-
328-
free(path_buf_wide);
327+
free(path_buf_wide);
329328

330-
if (*path_buf)
331-
return path_buf;
329+
if (*path_buf)
330+
return path_buf;
332331

333-
free(path_buf);
334-
return NULL;
335-
}
336-
}
337-
else
338-
{
339-
free(path_buf_wide);
340-
return strdup(str);
332+
free(path_buf);
333+
return NULL;
341334
}
342335
}
336+
else
337+
{
338+
free(path_buf_wide);
339+
return strdup(str);
340+
}
343341
}
344-
}
345-
else
346-
return strdup(str);
347342

348-
if (path_buf_wide)
349343
free(path_buf_wide);
344+
}
350345

351346
return NULL;
352347
}

0 commit comments

Comments
 (0)