mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-14 00:06:24 +01:00
g_string_replace: Don't replace empty string more than once per location
This matches the behaviour of Python `str.replace()`, and avoids carrying out 2**32 replacements before n wraps around, which is almost certainly not what we want. Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2452 Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
parent
7d35e49c42
commit
0a8c7e57ab
@ -995,6 +995,15 @@ g_string_replace (GString *string,
|
||||
g_string_insert (string, pos, replace);
|
||||
cur = string->str + pos + r_len;
|
||||
n++;
|
||||
/* Only match the empty string once at any given position, to
|
||||
* avoid infinite loops */
|
||||
if (f_len == 0)
|
||||
{
|
||||
if (cur[0] == '\0')
|
||||
break;
|
||||
else
|
||||
cur++;
|
||||
}
|
||||
if (n == limit)
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user