Do not concatenate empty strings with separator
This commit is contained in:
		
							parent
							
								
									a1781a451b
								
							
						
					
					
						commit
						a6301ff464
					
				| @ -76,9 +76,11 @@ char *string_replace_all(const char *needle, const char *replacement, | ||||
| 
 | ||||
| char *string_append(char *a, const char *b, const char *sep) | ||||
| { | ||||
|         if (!a) | ||||
|         if (!a || *a == '\0') { | ||||
|                 g_free(a); | ||||
|                 return g_strdup(b); | ||||
|         if (!b) | ||||
|         } | ||||
|         if (!b || *b == '\0') | ||||
|                 return a; | ||||
| 
 | ||||
|         char *new; | ||||
|  | ||||
| @ -83,6 +83,8 @@ TEST test_string_append(void) | ||||
| 
 | ||||
|         ASSERT_STR_EQ("text", (exp = string_append(g_strdup("text"), "", NULL))); | ||||
|         g_free(exp); | ||||
|         ASSERT_STR_EQ("text", (exp = string_append(g_strdup("text"), "", "_sep_"))); | ||||
|         g_free(exp); | ||||
| 
 | ||||
|         ASSERT_STR_EQ("b", (exp = string_append(g_strdup(""), "b", NULL))); | ||||
|         g_free(exp); | ||||
| @ -94,6 +96,8 @@ TEST test_string_append(void) | ||||
|         ASSERT_STR_EQ("a", (exp = string_append(g_strdup("a"), NULL, "_sep_"))); | ||||
|         g_free(exp); | ||||
| 
 | ||||
|         ASSERT_STR_EQ("", (exp = string_append(g_strdup(""), "", "_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
	 Benedikt Heine
						Benedikt Heine