From f6d6800962462eb08394918489934d799f4f620c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= Date: Wed, 15 Feb 2023 14:45:29 +0100 Subject: [PATCH] g_string_append_len_inline: fix implicit conversion changes signedness For: https://gitlab.gnome.org/GNOME/glib/-/issues/2919 --- glib/gstring.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/glib/gstring.h b/glib/gstring.h index 0a6af767a..55825c012 100644 --- a/glib/gstring.h +++ b/glib/gstring.h @@ -207,6 +207,8 @@ g_string_append_len_inline (GString *gstring, const char *val, gssize len) { + gsize len_unsigned; + if G_UNLIKELY (gstring == NULL) 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; 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; - if (G_LIKELY (val + len <= end || val > end + len)) - memcpy (end, val, len); + if (G_LIKELY (val + len_unsigned <= end || val > end + len_unsigned)) + memcpy (end, val, len_unsigned); else - memmove (end, val, len); - gstring->len += len; + memmove (end, val, len_unsigned); + gstring->len += len_unsigned; gstring->str[gstring->len] = 0; return gstring; }