1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Allow zero-length buffers in jv_parser_set_buf()

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).
This commit is contained in:
Nicolas Williams
2014-12-26 18:29:56 -06:00
parent c02fcc8fef
commit 46e3125e26

View 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) { 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) assert((p->curr_buf == 0 || p->curr_buf_pos == p->curr_buf_length)
&& "previous buffer not exhausted"); && "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]) { if ((unsigned char)*buf == UTF8_BOM[p->bom_strip_position]) {
// matched a BOM character // matched a BOM character
buf++; buf++;