From 9890daca797b31d34d97d953c512378aabe3d51f Mon Sep 17 00:00:00 2001 From: dequis Date: Sat, 11 Apr 2015 15:09:49 -0300 Subject: [PATCH] Handle nulls properly in the g_strcmp0() for glib<2.16 I wrote some tests to compare the behavior but I don't know where to put them, so i'm including them here: assert(g_strcmp0("a", "b") == -1); assert(g_strcmp0(NULL, "a") == -1); assert(g_strcmp0("a", NULL) == 1); assert(g_strcmp0("b", "a") == 1); assert(g_strcmp0("a", "a") == 0); assert(g_strcmp0(NULL, NULL) == 0); --- src/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.h b/src/common.h index 23d091a1..1b99753b 100644 --- a/src/common.h +++ b/src/common.h @@ -53,7 +53,7 @@ #endif #if !GLIB_CHECK_VERSION(2,16,0) -#define g_strcmp0(str1, str2) strcmp(str1, str2) +#define g_strcmp0(a, b) (!a ? -(a != b) : (!b ? (a != b) : strcmp(a, b))) #endif #ifdef USE_GC