Warnings when under GCC 3.4



When trying to build gnome-vfs with gcc 3.4 I get various errors (see
below); it looks like every instance of the VERIFY_STRING_RESULT with
NULL as the second arg causes a warning; this causes warnings in
methods/http-authn.c and in test/test-uri.c

The attached patch makes it build without warnings.

http-authn.c: In function `http_authn_self_test':
http-authn.c:503: warning: null argument where non-null required (arg 1)
http-authn.c:503: warning: null argument where non-null required (arg 2)
http-authn.c:503: warning: null argument where non-null required (arg 1)
http-authn.c:503: warning: null argument where non-null required (arg 2)
http-authn.c:527: warning: null argument where non-null required (arg 1)
http-authn.c:527: warning: null argument where non-null required (arg 2)
http-authn.c:527: warning: null argument where non-null required (arg 1)
http-authn.c:527: warning: null argument where non-null required (arg 2)
http-authn.c:538: warning: null argument where non-null required (arg 1)
http-authn.c:538: warning: null argument where non-null required (arg 2)
http-authn.c:538: warning: null argument where non-null required (arg 1)
http-authn.c:538: warning: null argument where non-null required (arg 2)
http-authn.c:543: warning: null argument where non-null required (arg 1)
http-authn.c:543: warning: null argument where non-null required (arg 2)
http-authn.c:543: warning: null argument where non-null required (arg 1)
http-authn.c:543: warning: null argument where non-null required (arg 2)

? daemon/gnome-vfs-daemon
? libgnomevfs/s-enum-types-c
? libgnomevfs/s-enum-types-h
Index: modules/http-authn.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/http-authn.c,v
retrieving revision 1.5
diff -u -p -r1.5 http-authn.c
--- modules/http-authn.c	26 Sep 2001 05:35:52 -0000	1.5
+++ modules/http-authn.c	18 May 2004 19:21:52 -0000
@@ -376,11 +376,24 @@ http_authn_get_header_for_uri (GnomeVFSU
 	return result;
 }
 
+static gboolean
+safe_string_equality (const char *a, const char *b)
+{
+	if (a != NULL) {
+		if (b!=NULL) {
+			return (0==strcmp (a, b));
+		} else {
+			return FALSE;
+		}
+	} else {
+		return (NULL==b);
+	}
+}
+
 #define VERIFY_STRING_RESULT(function, expected) \
 	G_STMT_START {											\
 		char *result = function; 								\
-		if (!((result == NULL && expected == NULL)						\
-		      || (result != NULL && expected != NULL && strcmp (result, (char *)expected) == 0))) {	\
+                if (!safe_string_equality(result, expected)) {                                          \
 			test_failed ("%s:%s:%s: returned '%s' expected '%s'", __FILE__, __LINE__, #function, result, expected);	\
 		}											\
 	} G_STMT_END
Index: test/test-uri.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/test/test-uri.c,v
retrieving revision 1.38
diff -u -p -r1.38 test-uri.c
--- test/test-uri.c	18 Jul 2003 21:37:47 -0000	1.38
+++ test/test-uri.c	18 May 2004 19:21:52 -0000
@@ -409,14 +409,26 @@ test_uri_is_parent_shallow (const char *
 	test_uri_is_parent_common (parent, item, FALSE, expected_result);
 }
 
+static gboolean
+safe_string_equality (const char *a, const char *b)
+{
+	if (a != NULL) {
+		if (b!=NULL) {
+			return (0==strcmp (a, b));
+		} else {
+			return FALSE;
+		}
+	} else {
+		return (NULL==b);
+	}
+}
+
 #define VERIFY_STRING_RESULT(function, expected) \
 	G_STMT_START {											\
 		char *result = function; 								\
-		if (!((result == NULL && expected == NULL)						\
-		      || (result != NULL && expected != NULL && strcmp (result, (char *)expected) == 0))) {	\
-			test_failed ("%s: returned '%s' expected '%s'", #function, result, expected);	\
+                if (!safe_string_equality(result, expected)) {                                          \
+			test_failed ("%s:%s:%s: returned '%s' expected '%s'", __FILE__, __LINE__, #function, result, expected);	\
 		}											\
-                g_free (result);                                                                      \
 	} G_STMT_END
 
 int


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]