aboutsummaryrefslogtreecommitdiffhomepage
path: root/fish_tests.cpp
diff options
context:
space:
mode:
authorGravatar Konrad Borowski <x.fix@o2.pl>2014-05-04 15:46:15 +0200
committerGravatar Konrad Borowski <x.fix@o2.pl>2014-05-04 15:48:50 +0200
commit16534ec64492b7c08e5837b9da83072452813f28 (patch)
tree720ef83c9e00938206b79e231bffbbfac5c66e0d /fish_tests.cpp
parent333fb1bf97e53725b730fa7047e1873cacceed44 (diff)
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.
Diffstat (limited to 'fish_tests.cpp')
-rw-r--r--fish_tests.cpp29
1 files changed, 12 insertions, 17 deletions
diff --git a/fish_tests.cpp b/fish_tests.cpp
index eca03097..f82633c6 100644
--- a/fish_tests.cpp
+++ b/fish_tests.cpp
@@ -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 */
+ err(L"w2u: %s: FAILED (rv: %lu, must be %lu)", descr, size, res);
+ goto finish;
+ }
- if (memcmp(mem, dst, size) != 0)
- {
- err(L"w2u: %s: BROKEN", descr);
- break;
- }
+ if (mem == NULL)
+ goto finish; /* OK */
+ if (memcmp(mem, dst, size) != 0)
+ {
+ err(L"w2u: %s: BROKEN", descr);
+ goto finish;
}
- while (0);
- if (mem != NULL);
+ finish:
free(mem);
}