Fix a possible crash in g_io_channel_read_chars

Patch by Rui Matos, https://bugzilla.gnome.org/show_bug.cgi?id=637759
This commit is contained in:
Matthias Clasen 2010-12-28 00:08:56 -05:00
parent bf1027f826
commit 702a96c281

View File

@ -1987,21 +1987,20 @@ g_io_channel_read_to_end (GIOChannel *channel,
* g_io_channel_read_chars: * g_io_channel_read_chars:
* @channel: a #GIOChannel * @channel: a #GIOChannel
* @buf: a buffer to read data into * @buf: a buffer to read data into
* @count: the size of the buffer. Note that the buffer may * @count: the size of the buffer. Note that the buffer may not be
* not be complelely filled even if there is data * complelely filled even if there is data in the buffer if the
* in the buffer if the remaining data is not a * remaining data is not a complete character.
* complete character. * @bytes_read: (allow-none): The number of bytes read. This may be
* @bytes_read: The number of bytes read. This may be zero even on * zero even on success if count < 6 and the channel's encoding
* success if count < 6 and the channel's encoding is non-%NULL. * is non-%NULL. This indicates that the next UTF-8 character is
* This indicates that the next UTF-8 character is too wide for * too wide for the buffer.
* the buffer.
* @error: a location to return an error of type #GConvertError * @error: a location to return an error of type #GConvertError
* or #GIOChannelError. * or #GIOChannelError.
* *
* Replacement for g_io_channel_read() with the new API. * Replacement for g_io_channel_read() with the new API.
* *
* Return value: the status of the operation. * Return value: the status of the operation.
**/ */
GIOStatus GIOStatus
g_io_channel_read_chars (GIOChannel *channel, g_io_channel_read_chars (GIOChannel *channel,
gchar *buf, gchar *buf,
@ -2013,12 +2012,12 @@ g_io_channel_read_chars (GIOChannel *channel,
gsize got_bytes; gsize got_bytes;
g_return_val_if_fail (channel != NULL, G_IO_STATUS_ERROR); g_return_val_if_fail (channel != NULL, G_IO_STATUS_ERROR);
g_return_val_if_fail ((error == NULL) || (*error == NULL), g_return_val_if_fail ((error == NULL) || (*error == NULL), G_IO_STATUS_ERROR);
G_IO_STATUS_ERROR);
g_return_val_if_fail (channel->is_readable, G_IO_STATUS_ERROR); g_return_val_if_fail (channel->is_readable, G_IO_STATUS_ERROR);
if (count == 0) if (count == 0)
{ {
if (bytes_read)
*bytes_read = 0; *bytes_read = 0;
return G_IO_STATUS_NORMAL; return G_IO_STATUS_NORMAL;
} }