summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCCode <chris.gcode@gmail.com>2023-01-16 13:08:42 +0000
committerPhilip Withnall <pwithnall@endlessos.org>2023-01-16 13:09:55 +0000
commitdfd070cea4c5cb1f6d7e4bf83c27cfd944a41761 (patch)
treeccf816018a3ba1c2655bc14f66e01ce78ea2701e
parent40233516bc2df49a1e540ab477ac0449320388b6 (diff)
downloadglib-dfd070cea4c5cb1f6d7e4bf83c27cfd944a41761.tar.gz
gfileutils: Use 'write' with 'count' <= max value of its return type
Limit `count` so that `write` can properly report the number of written bytes. Limits: - POSIX: `SSIZE_MAX` - Windows: `INT_MAX` Fixes: #2883
-rw-r--r--glib/gfileutils.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/glib/gfileutils.c b/glib/gfileutils.c
index f0c8f6776..722575ef6 100644
--- a/glib/gfileutils.c
+++ b/glib/gfileutils.c
@@ -1143,7 +1143,13 @@ write_to_file (const gchar *contents,
{
gssize s;
- s = write (fd, contents, MIN (length, G_MAXSSIZE));
+#ifdef G_OS_WIN32
+ /* 'write' on windows uses int types, so limit count to G_MAXINT */
+ s = write (fd, contents, MIN (length, (gsize) G_MAXINT));
+#else
+ /* Limit count to G_MAXSSIZE to fit into the return value. */
+ s = write (fd, contents, MIN (length, (gsize) G_MAXSSIZE));
+#endif
if (s < 0)
{