diff --git a/glib/giochannel.c b/glib/giochannel.c index 4fba3a5b0..1956e9dc6 100644 --- a/glib/giochannel.c +++ b/glib/giochannel.c @@ -2180,6 +2180,7 @@ g_io_channel_write_chars (GIOChannel *channel, gsize *bytes_written, GError **error) { + gsize count_unsigned; GIOStatus status; gssize wrote_bytes = 0; @@ -2190,8 +2191,9 @@ g_io_channel_write_chars (GIOChannel *channel, if ((count < 0) && buf) count = strlen (buf); - - if (count == 0) + count_unsigned = count; + + if (count_unsigned == 0) { if (bytes_written) *bytes_written = 0; @@ -2199,7 +2201,7 @@ g_io_channel_write_chars (GIOChannel *channel, } g_return_val_if_fail (buf != NULL, G_IO_STATUS_ERROR); - g_return_val_if_fail (count > 0, G_IO_STATUS_ERROR); + g_return_val_if_fail (count_unsigned > 0, G_IO_STATUS_ERROR); /* Raw write case */ @@ -2210,7 +2212,8 @@ g_io_channel_write_chars (GIOChannel *channel, g_assert (!channel->write_buf || channel->write_buf->len == 0); g_assert (channel->partial_write_buf[0] == '\0'); - status = channel->funcs->io_write (channel, buf, count, &tmp_bytes, error); + status = channel->funcs->io_write (channel, buf, count_unsigned, + &tmp_bytes, error); if (bytes_written) *bytes_written = tmp_bytes; @@ -2286,7 +2289,7 @@ g_io_channel_write_chars (GIOChannel *channel, if (!channel->encoding) { - gssize write_this = MIN (space_in_buf, count - wrote_bytes); + gssize write_this = MIN (space_in_buf, count_unsigned - wrote_bytes); g_string_append_len (channel->write_buf, buf, write_this); buf += write_this; @@ -2306,7 +2309,7 @@ g_io_channel_write_chars (GIOChannel *channel, from_buf = channel->partial_write_buf; from_buf_old_len = strlen (channel->partial_write_buf); g_assert (from_buf_old_len > 0); - from_buf_len = MIN (6, from_buf_old_len + count); + from_buf_len = MIN (6, from_buf_old_len + count_unsigned); memcpy (channel->partial_write_buf + from_buf_old_len, buf, from_buf_len - from_buf_old_len); @@ -2314,7 +2317,7 @@ g_io_channel_write_chars (GIOChannel *channel, else { from_buf = buf; - from_buf_len = count - wrote_bytes; + from_buf_len = count_unsigned - wrote_bytes; from_buf_old_len = 0; } @@ -2404,7 +2407,7 @@ reconvert: memcpy (channel->partial_write_buf, from_buf, left_len); channel->partial_write_buf[left_len] = '\0'; if (bytes_written) - *bytes_written = count; + *bytes_written = count_unsigned; return G_IO_STATUS_NORMAL; } @@ -2416,12 +2419,12 @@ reconvert: * less than a full character */ - g_assert (count == from_buf_len - from_buf_old_len); + g_assert (count_unsigned == from_buf_len - from_buf_old_len); channel->partial_write_buf[from_buf_len] = '\0'; if (bytes_written) - *bytes_written = count; + *bytes_written = count_unsigned; return G_IO_STATUS_NORMAL; } @@ -2483,7 +2486,7 @@ reconvert: } if (bytes_written) - *bytes_written = count; + *bytes_written = count_unsigned; return G_IO_STATUS_NORMAL; }