mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-26 20:22:11 +01:00
g_string_append_len_inline: fix implicit conversion changes signedness
For: https://gitlab.gnome.org/GNOME/glib/-/issues/2919
This commit is contained in:
parent
e784bedd40
commit
f6d6800962
@ -207,6 +207,8 @@ g_string_append_len_inline (GString *gstring,
|
|||||||
const char *val,
|
const char *val,
|
||||||
gssize len)
|
gssize len)
|
||||||
{
|
{
|
||||||
|
gsize len_unsigned;
|
||||||
|
|
||||||
if G_UNLIKELY (gstring == NULL)
|
if G_UNLIKELY (gstring == NULL)
|
||||||
return g_string_append_len (gstring, val, len);
|
return g_string_append_len (gstring, val, len);
|
||||||
|
|
||||||
@ -214,16 +216,18 @@ g_string_append_len_inline (GString *gstring,
|
|||||||
return (len != 0) ? g_string_append_len (gstring, val, len) : gstring;
|
return (len != 0) ? g_string_append_len (gstring, val, len) : gstring;
|
||||||
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
len = strlen (val);
|
len_unsigned = strlen (val);
|
||||||
|
else
|
||||||
|
len_unsigned = (gsize) len;
|
||||||
|
|
||||||
if (G_LIKELY (gstring->len + len < gstring->allocated_len))
|
if (G_LIKELY (gstring->len + len_unsigned < gstring->allocated_len))
|
||||||
{
|
{
|
||||||
char *end = gstring->str + gstring->len;
|
char *end = gstring->str + gstring->len;
|
||||||
if (G_LIKELY (val + len <= end || val > end + len))
|
if (G_LIKELY (val + len_unsigned <= end || val > end + len_unsigned))
|
||||||
memcpy (end, val, len);
|
memcpy (end, val, len_unsigned);
|
||||||
else
|
else
|
||||||
memmove (end, val, len);
|
memmove (end, val, len_unsigned);
|
||||||
gstring->len += len;
|
gstring->len += len_unsigned;
|
||||||
gstring->str[gstring->len] = 0;
|
gstring->str[gstring->len] = 0;
|
||||||
return gstring;
|
return gstring;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user