diff options
author | Sam Thursfield <sam@afuera.me.uk> | 2020-12-27 13:47:36 +0100 |
---|---|---|
committer | Sam Thursfield <sam@afuera.me.uk> | 2020-12-27 14:01:40 +0100 |
commit | 517a22dcf6dcb9226fdfc805dedcca3febf06cf5 (patch) | |
tree | cceba73eb6339d73e84497fba86fc61727d59590 /tests | |
parent | 265e27beb06945503422845f460cadadaab6b675 (diff) | |
download | libmediaart-517a22dcf6dcb9226fdfc805dedcca3febf06cf5.tar.gz |
Rationalize NULL/empty string handling in media_art_strip_invalid_entities()
We return NULL if input is NULL and a newly allocated empty string if
input is "". Some comments disagreed with this, and it's possible the
change causes a memory leak in some app, but the alternative of returning
NULL when passed "" is dangerous as some code may free the return value
in this case. (In fact, libmediaart itself does so).
Also, make behaviour occur independently of whether
`G_ENABLE_CONSISTENCY_CHECKS` was defined at build time.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/mediaarttest.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/tests/mediaarttest.c b/tests/mediaarttest.c index cef36c2..93ac684 100644 --- a/tests/mediaarttest.c +++ b/tests/mediaarttest.c @@ -112,18 +112,20 @@ test_mediaart_stripping_failures_subprocess (void) static void test_mediaart_stripping_failures (void) { - gchar *stripped = NULL; + gchar *stripped, *input = NULL; /* a. Return NULL for NULL (subprocess) - * b. Return NULL for "" + * b. Return a copy for "" */ - stripped = media_art_strip_invalid_entities (""); - g_assert (stripped); - g_assert_cmpstr (stripped, ==, ""); + stripped = media_art_strip_invalid_entities (NULL); + g_assert (!stripped); - g_test_trap_subprocess ("/mediaart/stripping_failures/subprocess", 0, 0); - g_test_trap_assert_failed (); - g_test_trap_assert_stderr ("*assertion 'original != NULL' failed*"); + input = ""; + stripped = media_art_strip_invalid_entities (input); + g_assert (stripped); + g_assert (stripped != input); + g_assert (strcmp(stripped, "") == 0); + g_free (stripped); } |