[gaim-migrate @ 15457]

Thu, 02 Feb 2006 18:42:28 +0000

author
Richard Laager <rlaager@pidgin.im>
date
Thu, 02 Feb 2006 18:42:28 +0000
changeset 13096
03d1402b31ea
parent 13095
bb0d9b82a3bf
child 13097
7926f8363634

[gaim-migrate @ 15457]
Add some g_return_val_if_fail() guards to our local implementations of g_str_has_prefix() and g_str_has_suffix(). Glib has these, and it may help prevent crashes.

src/util.c file | annotate | diff | comparison | revisions
--- a/src/util.c	Thu Feb 02 13:18:18 2006 +0000
+++ b/src/util.c	Thu Feb 02 18:42:28 2006 +0000
@@ -2484,10 +2484,10 @@
 #if GLIB_CHECK_VERSION(2,2,0)
 	return g_str_has_prefix(s, p);
 #else
-	if (!strncmp(s, p, strlen(p)))
-		return TRUE;
-
-	return FALSE;
+	g_return_val_if_fail(s != NULL, FALSE);
+	g_return_val_if_fail(p != NULL, FALSE);
+
+	return (!strncmp(s, p, strlen(p)));
 #endif
 }
 
@@ -2497,12 +2497,13 @@
 #if GLIB_CHECK_VERSION(2,2,0)
 	return g_str_has_suffix(s, x);
 #else
-	int off = strlen(s) - strlen(x);
-
-	if (off >= 0 && !strcmp(s + off, x))
-		return TRUE;
-
-	return FALSE;
+	int off;
+
+	g_return_val_if_fail(s != NULL, FALSE);
+	g_return_val_if_fail(x != NULL, FALSE);
+
+	off = strlen(s) - strlen(x);
+	return (off >= 0 && !strcmp(s + off, x));
 #endif
 }
 

mercurial