Fixing signedness in glib/giochannel.c

In file included from glib/glibconfig.h:9,
                 from glib/gtypes.h:32,
                 from glib/gquark.h:32,
                 from glib/gerror.h:28,
                 from glib/gconvert.h:32,
                 from glib/giochannel.h:32,
                 from glib/giochannel.c:37:
glib/giochannel.c: In function ‘g_io_channel_write_chars’:
glib/gmacros.h:351:26: error: comparison of integer expressions of different signedness: ‘gsize’ {aka ‘long unsigned int’} and ‘gssize’ {aka ‘long int’} [-Werror=sign-compare]
 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
                          ^
glib/giochannel.c:2285:31: note: in expansion of macro ‘MIN’
           gssize write_this = MIN (space_in_buf, count - wrote_bytes);
                               ^~~
glib/gmacros.h:351:41: error: operand of ?: changes signedness from ‘gssize’ {aka ‘long int’} to ‘gsize’ {aka ‘long unsigned int’} due to unsignedness of other operand [-Werror=sign-compare]
 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
                                         ^~~
glib/giochannel.c:2285:31: note: in expansion of macro ‘MIN’
           gssize write_this = MIN (space_in_buf, count - wrote_bytes);
                               ^~~
glib/giochannel.c:2415:41: error: comparison of integer expressions of different signedness: ‘gssize’ {aka ‘long int’} and ‘gsize’ {aka ‘long unsigned int’} [-Werror=sign-compare]
                         g_assert (count == from_buf_len - from_buf_old_len);
                                         ^~
glib/gmacros.h:455:25: note: in definition of macro ‘G_LIKELY’
 #define G_LIKELY(expr) (expr)
                         ^~~~
glib/giochannel.c:2415:25: note: in expansion of macro ‘g_assert’
                         g_assert (count == from_buf_len - from_buf_old_len);
                         ^~~~~~~~
This commit is contained in:
Emmanuel Fleury 2019-01-31 18:43:59 +01:00
parent 0fea1a4775
commit 2f9e6e977a

View File

@ -2180,6 +2180,7 @@ g_io_channel_write_chars (GIOChannel *channel,
gsize *bytes_written, gsize *bytes_written,
GError **error) GError **error)
{ {
gsize count_unsigned;
GIOStatus status; GIOStatus status;
gssize wrote_bytes = 0; gssize wrote_bytes = 0;
@ -2190,8 +2191,9 @@ g_io_channel_write_chars (GIOChannel *channel,
if ((count < 0) && buf) if ((count < 0) && buf)
count = strlen (buf); count = strlen (buf);
count_unsigned = count;
if (count == 0)
if (count_unsigned == 0)
{ {
if (bytes_written) if (bytes_written)
*bytes_written = 0; *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 (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 */ /* 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->write_buf || channel->write_buf->len == 0);
g_assert (channel->partial_write_buf[0] == '\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) if (bytes_written)
*bytes_written = tmp_bytes; *bytes_written = tmp_bytes;
@ -2286,7 +2289,7 @@ g_io_channel_write_chars (GIOChannel *channel,
if (!channel->encoding) 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); g_string_append_len (channel->write_buf, buf, write_this);
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 = channel->partial_write_buf;
from_buf_old_len = strlen (channel->partial_write_buf); from_buf_old_len = strlen (channel->partial_write_buf);
g_assert (from_buf_old_len > 0); 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, memcpy (channel->partial_write_buf + from_buf_old_len, buf,
from_buf_len - from_buf_old_len); from_buf_len - from_buf_old_len);
@ -2314,7 +2317,7 @@ g_io_channel_write_chars (GIOChannel *channel,
else else
{ {
from_buf = buf; from_buf = buf;
from_buf_len = count - wrote_bytes; from_buf_len = count_unsigned - wrote_bytes;
from_buf_old_len = 0; from_buf_old_len = 0;
} }
@ -2404,7 +2407,7 @@ reconvert:
memcpy (channel->partial_write_buf, from_buf, left_len); memcpy (channel->partial_write_buf, from_buf, left_len);
channel->partial_write_buf[left_len] = '\0'; channel->partial_write_buf[left_len] = '\0';
if (bytes_written) if (bytes_written)
*bytes_written = count; *bytes_written = count_unsigned;
return G_IO_STATUS_NORMAL; return G_IO_STATUS_NORMAL;
} }
@ -2416,12 +2419,12 @@ reconvert:
* less than a full character * 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'; channel->partial_write_buf[from_buf_len] = '\0';
if (bytes_written) if (bytes_written)
*bytes_written = count; *bytes_written = count_unsigned;
return G_IO_STATUS_NORMAL; return G_IO_STATUS_NORMAL;
} }
@ -2483,7 +2486,7 @@ reconvert:
} }
if (bytes_written) if (bytes_written)
*bytes_written = count; *bytes_written = count_unsigned;
return G_IO_STATUS_NORMAL; return G_IO_STATUS_NORMAL;
} }