From 856265fe669be15cfd156b720cc6614c4ae4f7a5 Mon Sep 17 00:00:00 2001 From: Emmanuel Fleury Date: Thu, 27 Aug 2020 14:26:20 +0200 Subject: [PATCH 1/2] Fixing signedness warning in glib/gfileutils.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit glib/gfileutils.c: In function ‘write_to_file’: glib/gfileutils.c:1176:19: error: comparison of integer expressions of different signedness: ‘gssize’ {aka ‘long int’} and ‘gsize’ {aka ‘long unsigned int’} [-Werror=sign-compare] 1176 | g_assert (s <= length); | ^~ glib/gmacros.h:939:25: note: in definition of macro ‘G_LIKELY’ 939 | #define G_LIKELY(expr) (expr) | ^~~~ glib/gfileutils.c:1176:7: note: in expansion of macro ‘g_assert’ 1176 | g_assert (s <= length); | ^~~~~~~~ Related to issue #1735 (Get back to a -werror build) --- glib/gfileutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glib/gfileutils.c b/glib/gfileutils.c index 2993eacc3..8992203d6 100644 --- a/glib/gfileutils.c +++ b/glib/gfileutils.c @@ -1173,7 +1173,7 @@ write_to_file (const gchar *contents, return FALSE; } - g_assert (s <= length); + g_assert ((gsize) s <= length); contents += s; length -= s; From dae128e6bb83f27605430b5b5661ba331d102926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 27 Aug 2020 17:42:28 +0200 Subject: [PATCH 2/2] Don't pass more than G_MAXSSIZE bytes at once to write() in glib/gfileutils.c Behaviour in that case is implementation-defined and how many bytes were actually written can't be expressed by the return value anymore. Instead do a short write of G_MAXSSIZE bytes and let the existing loop for handling short writes takes care of the remaining length. --- glib/gfileutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glib/gfileutils.c b/glib/gfileutils.c index 8992203d6..46f200ddf 100644 --- a/glib/gfileutils.c +++ b/glib/gfileutils.c @@ -1157,7 +1157,7 @@ write_to_file (const gchar *contents, { gssize s; - s = write (fd, contents, length); + s = write (fd, contents, MIN (length, G_MAXSSIZE)); if (s < 0) {