[devhelp] Don't assume we can always read BYTES_PER_READ



commit 5ac785077f2eb2c1b5574537586170f0fd8be6c2
Author: William Jon McCann <william jon mccann gmail com>
Date:   Sat Feb 8 20:15:34 2014 -0500

    Don't assume we can always read BYTES_PER_READ
    
    If the next unicode character is too wide for the buffer the
    total number of bytes read will be less than BYTES_PER_READ.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=723933

 src/dh-parser.c |   15 ++++++---------
 1 files changed, 6 insertions(+), 9 deletions(-)
---
diff --git a/src/dh-parser.c b/src/dh-parser.c
index 3faa171..35d3179 100644
--- a/src/dh-parser.c
+++ b/src/dh-parser.c
@@ -165,7 +165,6 @@ parser_start_node_book (DhParser             *parser,
                             NULL,
                             uri);
         g_free (base);
-
         *parser->keywords = g_list_prepend (*parser->keywords, dh_link_ref (link));
 
         parser->book_node = g_node_new (dh_link_ref (link));
@@ -596,26 +595,24 @@ dh_parser_read_file (const gchar  *path,
                         GIOStatus io_status;
                         gsize     bytes_read;
 
-                        io_status = g_io_channel_read_chars (io, buf, BYTES_PER_READ,
-                                                             &bytes_read, error);
+                        do {
+                                io_status = g_io_channel_read_chars (io, buf, BYTES_PER_READ,
+                                                                     &bytes_read, error);
+                        } while (io_status == G_IO_STATUS_AGAIN);
+
                         if (io_status == G_IO_STATUS_ERROR) {
                                 result = FALSE;
                                 goto exit;
                         }
-                        if (io_status != G_IO_STATUS_NORMAL) {
+                        if (io_status == G_IO_STATUS_EOF || io_status == G_IO_STATUS_ERROR) {
                                 break;
                         }
-
                         g_markup_parse_context_parse (parser->context, buf,
                                                       bytes_read, error);
                         if (error != NULL && *error != NULL) {
                                 result = FALSE;
                                 goto exit;
                         }
-
-                        if (bytes_read < BYTES_PER_READ) {
-                                break;
-                        }
                 }
         }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]