[gtk/wip/otte/json: 77/85] jsonparser: Don't treat \0 as eof




commit eee1ab678448cce990994c990cfc0c607d585d95
Author: Benjamin Otte <otte redhat com>
Date:   Sun Dec 5 18:06:02 2021 +0100

    jsonparser: Don't treat \0 as eof
    
    Instead, treat it as regular part of the data and emit errors when we
    encounter it.

 gtk/json/gtkjsonparser.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
---
diff --git a/gtk/json/gtkjsonparser.c b/gtk/json/gtkjsonparser.c
index 6cda09ffb2..3a8e1ab06b 100644
--- a/gtk/json/gtkjsonparser.c
+++ b/gtk/json/gtkjsonparser.c
@@ -393,7 +393,7 @@ gtk_json_parser_schema_error (GtkJsonParser *self,
 static gboolean
 gtk_json_parser_is_eof (GtkJsonParser *self)
 {
-  return self->reader >= self->end || *self->reader == '\0';
+  return self->reader >= self->end;
 }
 
 static gsize
@@ -900,6 +900,8 @@ gtk_json_parser_parse_value (GtkJsonParser *self)
         end++;
       gtk_json_parser_syntax_error_at (self, self->block->value, end, "Numbers may not start with '%c'", 
*self->block->value);
     }
+  else if (*self->reader == 0)
+    gtk_json_parser_syntax_error (self, "Unexpected nul byte in document");
   else
     gtk_json_parser_syntax_error (self, "Expected a value");
   return FALSE;
@@ -1070,10 +1072,10 @@ gtk_json_parser_next (GtkJsonParser *self)
       if (gtk_json_parser_is_eof (self))
         {
           self->block->value = NULL;
-          if (gtk_json_parser_remaining (self))
-            {
-              gtk_json_parser_syntax_error (self, "Unexpected nul byte in document");
-            }
+        }
+      else if (*self->reader == 0)
+        {
+          gtk_json_parser_syntax_error (self, "Unexpected nul byte in document");
         }
       else
         {


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