2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 06:15:47 +00:00

json: Correct position tracking in JSON parser implementations.

When json_lex_input() returns false, the parser does not consume the byte
passed in.  That byte will get processed again in the next iteration of
the json_parser_feed() loop.  Therefore, until now, this code has
double-counted bytes that cause a false return from json_lex_input().

This fixes the problem.  Every input byte is now counted only once.

Signed-off-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
Ben Pfaff
2012-04-26 09:48:28 -07:00
parent 3a4548cfb2
commit c640c04f64
3 changed files with 19 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2010, 2011 Nicira Networks
# Copyright (c) 2010, 2011, 2012 Nicira Networks
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -420,13 +420,6 @@ class Parser(object):
return True
def __lex_input(self, c):
self.byte_number += 1
if c == '\n':
self.column_number = 0
self.line_number += 1
else:
self.column_number += 1
eat = self.lex_state(self, c)
assert eat is True or eat is False
return eat
@@ -557,7 +550,16 @@ class Parser(object):
while True:
if self.done or i >= len(s):
return i
if self.__lex_input(s[i]):
c = s[i]
if self.__lex_input(c):
self.byte_number += 1
if c == '\n':
self.column_number = 0
self.line_number += 1
else:
self.column_number += 1
i += 1
def is_done(self):