summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip@tecnocode.co.uk>2023-01-16 13:08:43 +0000
committerPhilip Withnall <philip@tecnocode.co.uk>2023-01-16 13:08:43 +0000
commitf7a02efbb7a1e7fd792c4ebd1b1918b494b7234e (patch)
tree0afc424ef35745c1ae6d56473af2aaf3ea30e3ef
parent26728b4ecc8fa69686b1782638685befaf70f8ea (diff)
parente9e4d52de8a8424a11f61512a75902ab06f29375 (diff)
downloadglib-f7a02efbb7a1e7fd792c4ebd1b1918b494b7234e.tar.gz
Merge branch 'issue_2883b' into 'main'
Use 'write' with 'count' <= max value of its return type Closes #2883 See merge request GNOME/glib!3200
-rw-r--r--glib/gfileutils.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/glib/gfileutils.c b/glib/gfileutils.c
index 44c22f3ee..131484901 100644
--- a/glib/gfileutils.c
+++ b/glib/gfileutils.c
@@ -1143,8 +1143,13 @@ write_to_file (const gchar *contents,
{
gssize s;
- s = write (fd, contents, MIN (length, G_MAXSIZE));
-
+#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)
{
int saved_errno = errno;