Check for b value if null in string_append
This avoids "a", NULL, "sep" to come to "asep" instead of "a".
This commit is contained in:
parent
8b11113be1
commit
a1781a451b
@ -78,6 +78,8 @@ char *string_append(char *a, const char *b, const char *sep)
|
||||
{
|
||||
if (!a)
|
||||
return g_strdup(b);
|
||||
if (!b)
|
||||
return a;
|
||||
|
||||
char *new;
|
||||
if (!sep)
|
||||
|
@ -91,6 +91,8 @@ TEST test_string_append(void)
|
||||
|
||||
ASSERT_STR_EQ("a", (exp = string_append(g_strdup("a"), "", NULL)));
|
||||
g_free(exp);
|
||||
ASSERT_STR_EQ("a", (exp = string_append(g_strdup("a"), NULL, "_sep_")));
|
||||
g_free(exp);
|
||||
|
||||
ASSERT_EQ(NULL, (exp = string_append(NULL, NULL, "_sep_")));
|
||||
g_free(exp);
|
||||
|
Loading…
x
Reference in New Issue
Block a user