From 8024c07a0e3fda5b95c6cf3d67d4c86eb25d2ef2 Mon Sep 17 00:00:00 2001 From: Daniel Elstner Date: Sat, 2 Nov 2002 00:14:55 +0000 Subject: [PATCH] Fix left_len calculation in the from UTF-8 to UTF-8 case: left_len should 2002-11-02 Daniel Elstner * glib/giochannel.c (g_io_channel_write_chars): Fix left_len calculation in the from UTF-8 to UTF-8 case: left_len should be the number of bytes left in the input buffer rather than channel->write_buf. (#96373) --- ChangeLog | 7 +++++++ ChangeLog.pre-2-10 | 7 +++++++ ChangeLog.pre-2-12 | 7 +++++++ ChangeLog.pre-2-2 | 7 +++++++ ChangeLog.pre-2-4 | 7 +++++++ ChangeLog.pre-2-6 | 7 +++++++ ChangeLog.pre-2-8 | 7 +++++++ glib/giochannel.c | 15 ++++++++------- 8 files changed, 57 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index ed112c0..14fdf85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-11-02 Daniel Elstner + + * glib/giochannel.c (g_io_channel_write_chars): Fix left_len + calculation in the from UTF-8 to UTF-8 case: left_len should + be the number of bytes left in the input buffer rather than + channel->write_buf. (#96373) + 2002-10-27 Tor Lillqvist * configure.in (G_MODULE_LDFLAGS): Don't set on Win32, only causes diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index ed112c0..14fdf85 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +2002-11-02 Daniel Elstner + + * glib/giochannel.c (g_io_channel_write_chars): Fix left_len + calculation in the from UTF-8 to UTF-8 case: left_len should + be the number of bytes left in the input buffer rather than + channel->write_buf. (#96373) + 2002-10-27 Tor Lillqvist * configure.in (G_MODULE_LDFLAGS): Don't set on Win32, only causes diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index ed112c0..14fdf85 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,10 @@ +2002-11-02 Daniel Elstner + + * glib/giochannel.c (g_io_channel_write_chars): Fix left_len + calculation in the from UTF-8 to UTF-8 case: left_len should + be the number of bytes left in the input buffer rather than + channel->write_buf. (#96373) + 2002-10-27 Tor Lillqvist * configure.in (G_MODULE_LDFLAGS): Don't set on Win32, only causes diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index ed112c0..14fdf85 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,10 @@ +2002-11-02 Daniel Elstner + + * glib/giochannel.c (g_io_channel_write_chars): Fix left_len + calculation in the from UTF-8 to UTF-8 case: left_len should + be the number of bytes left in the input buffer rather than + channel->write_buf. (#96373) + 2002-10-27 Tor Lillqvist * configure.in (G_MODULE_LDFLAGS): Don't set on Win32, only causes diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index ed112c0..14fdf85 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,10 @@ +2002-11-02 Daniel Elstner + + * glib/giochannel.c (g_io_channel_write_chars): Fix left_len + calculation in the from UTF-8 to UTF-8 case: left_len should + be the number of bytes left in the input buffer rather than + channel->write_buf. (#96373) + 2002-10-27 Tor Lillqvist * configure.in (G_MODULE_LDFLAGS): Don't set on Win32, only causes diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index ed112c0..14fdf85 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,10 @@ +2002-11-02 Daniel Elstner + + * glib/giochannel.c (g_io_channel_write_chars): Fix left_len + calculation in the from UTF-8 to UTF-8 case: left_len should + be the number of bytes left in the input buffer rather than + channel->write_buf. (#96373) + 2002-10-27 Tor Lillqvist * configure.in (G_MODULE_LDFLAGS): Don't set on Win32, only causes diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index ed112c0..14fdf85 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +2002-11-02 Daniel Elstner + + * glib/giochannel.c (g_io_channel_write_chars): Fix left_len + calculation in the from UTF-8 to UTF-8 case: left_len should + be the number of bytes left in the input buffer rather than + channel->write_buf. (#96373) + 2002-10-27 Tor Lillqvist * configure.in (G_MODULE_LDFLAGS): Don't set on Win32, only causes diff --git a/glib/giochannel.c b/glib/giochannel.c index b463a24..9708b7a 100644 --- a/glib/giochannel.c +++ b/glib/giochannel.c @@ -2058,15 +2058,16 @@ reconvert: if (!g_utf8_validate (from_buf, try_len, &badchar)) { gunichar try_char; + gsize incomplete_len = from_buf + try_len - badchar; - left_len = from_buf + try_len - badchar; + left_len = from_buf + from_buf_len - badchar; - try_char = g_utf8_get_char_validated (badchar, left_len); + try_char = g_utf8_get_char_validated (badchar, incomplete_len); switch (try_char) { case -2: - g_assert (left_len < 6); + g_assert (incomplete_len < 6); if (try_len == from_buf_len) { errnum = EINVAL; @@ -2075,7 +2076,7 @@ reconvert: else { errnum = 0; - err = (size_t) -1; + err = (size_t) 0; } break; case -1: @@ -2094,12 +2095,12 @@ reconvert: { err = (size_t) 0; errnum = 0; - left_len = 0; + left_len = from_buf_len - try_len; } g_string_append_len (channel->write_buf, from_buf, - try_len - left_len); - from_buf += try_len - left_len; + from_buf_len - left_len); + from_buf += from_buf_len - left_len; } else { -- 2.7.4