mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-13 15:56:23 +01:00
g_str_has_prefix: don't call strlen(str)
There's no reason to check the length of @str in g_str_has_prefix(), since if it's shorter than @prefix, the strncmp() will fail anyway. And besides making the function less efficient, it also breaks code like: if (buf->len >=3 && g_str_has_prefix (buf->data, "foo")) ... which really looks like it ought to work whether buf->data is nul-terminated or not. https://bugzilla.gnome.org/show_bug.cgi?id=727890
This commit is contained in:
parent
0e44b29340
commit
eec507c159
@ -2794,19 +2794,10 @@ gboolean
|
||||
g_str_has_prefix (const gchar *str,
|
||||
const gchar *prefix)
|
||||
{
|
||||
int str_len;
|
||||
int prefix_len;
|
||||
|
||||
g_return_val_if_fail (str != NULL, FALSE);
|
||||
g_return_val_if_fail (prefix != NULL, FALSE);
|
||||
|
||||
str_len = strlen (str);
|
||||
prefix_len = strlen (prefix);
|
||||
|
||||
if (str_len < prefix_len)
|
||||
return FALSE;
|
||||
|
||||
return strncmp (str, prefix, prefix_len) == 0;
|
||||
return strncmp (str, prefix, strlen (prefix)) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user