]> granicus.if.org Git - jq/commitdiff
Allow zero-length buffers in jv_parser_set_buf()
authorNicolas Williams <nico@cryptonector.com>
Sat, 27 Dec 2014 00:29:56 +0000 (18:29 -0600)
committerNicolas Williams <nico@cryptonector.com>
Sat, 27 Dec 2014 04:56:48 +0000 (22:56 -0600)
If the caller is at EOF and has no more bytes to feed the parser, how is
the parser to be told about the EOF condition?  A small fix to allow
zero-length buffers in jv_parser_set_buf() fixes this problem (it also
makes it easier to deal with async I/O: feed the parser whatever is
available, including nothing).

jv_parse.c

index 0a06dc18ceda5f0afd899e29d0db253403c8b5d4..3ed04f78650a530d82195d72e874755c7832f1f5 100644 (file)
@@ -419,7 +419,7 @@ static const unsigned char UTF8_BOM[] = {0xEF,0xBB,0xBF};
 void jv_parser_set_buf(struct jv_parser* p, const char* buf, int length, int is_partial) {
   assert((p->curr_buf == 0 || p->curr_buf_pos == p->curr_buf_length)
          && "previous buffer not exhausted");
-  while (p->bom_strip_position < sizeof(UTF8_BOM)) {
+  while (length > 0 && p->bom_strip_position < sizeof(UTF8_BOM)) {
     if ((unsigned char)*buf == UTF8_BOM[p->bom_strip_position]) {
       // matched a BOM character
       buf++;