mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Improve test_wchar2utf8().
Currently it contains strange code like using `do` loop in order to avoid `goto`s (they aren't evil, honestly), the pointless `if (mem)` conditional which doesn't even work (had semicolon for some reason). You may think this code had a bug where the code didn't check for the pointer to be null before calling `free`, but this is not the case, as according to C and C++ standard, `free` should allow `NULL` pointers, and ignore them.
This commit is contained in:
parent
333fb1bf97
commit
16534ec644
1 changed files with 14 additions and 19 deletions
|
@ -1021,28 +1021,23 @@ static void test_wchar2utf8(const wchar_t *src, size_t slen, const char *dst, si
|
|||
}
|
||||
}
|
||||
|
||||
do
|
||||
size = wchar_to_utf8(src, slen, mem, dlen, flags);
|
||||
if (res != size)
|
||||
{
|
||||
size = wchar_to_utf8(src, slen, mem, dlen, flags);
|
||||
if (res != size)
|
||||
{
|
||||
err(L"w2u: %s: FAILED (rv: %lu, must be %lu)", descr, size, res);
|
||||
break;
|
||||
}
|
||||
|
||||
if (mem == NULL)
|
||||
break; /* OK */
|
||||
|
||||
if (memcmp(mem, dst, size) != 0)
|
||||
{
|
||||
err(L"w2u: %s: BROKEN", descr);
|
||||
break;
|
||||
}
|
||||
|
||||
err(L"w2u: %s: FAILED (rv: %lu, must be %lu)", descr, size, res);
|
||||
goto finish;
|
||||
}
|
||||
while (0);
|
||||
|
||||
if (mem != NULL);
|
||||
if (mem == NULL)
|
||||
goto finish; /* OK */
|
||||
|
||||
if (memcmp(mem, dst, size) != 0)
|
||||
{
|
||||
err(L"w2u: %s: BROKEN", descr);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
finish:
|
||||
free(mem);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue