[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v1][ 11/14] json-lexer: fix flushing logic to not al
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PATCH v1][ 11/14] json-lexer: fix flushing logic to not always go to error state |
Date: |
Wed, 1 Jun 2011 12:14:57 -0500 |
Currently we flush the lexer by passing in a NULL character. This
generally forces the lexer to go to the corresponding TERMINAL() state
for whatever token type it is currently parsing, emits the token to the
parser, then puts the lexer back into IN_START state. However, since a
NULL character causes char_consumed to be 0, we always do a second pass
after this, which puts us in the IN_ERROR state. Fix this behavior by
adding a "flush" flag that tells the lexer not to do a more than 1
iteration.
Signed-off-by: Michael Roth <address@hidden>
---
json-lexer.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/json-lexer.c b/json-lexer.c
index a5bbe9e..6b49047 100644
--- a/json-lexer.c
+++ b/json-lexer.c
@@ -274,7 +274,7 @@ void json_lexer_init(JSONLexer *lexer, JSONLexerEmitter
func)
lexer->x = lexer->y = 0;
}
-static int json_lexer_feed_char(JSONLexer *lexer, char ch)
+static int json_lexer_feed_char(JSONLexer *lexer, char ch, bool flush)
{
int char_consumed, new_state;
@@ -313,7 +313,7 @@ static int json_lexer_feed_char(JSONLexer *lexer, char ch)
break;
}
lexer->state = new_state;
- } while (!char_consumed);
+ } while (!char_consumed && !flush);
/* Do not let a single token grow to an arbitrarily large size,
* this is a security consideration.
@@ -335,7 +335,7 @@ int json_lexer_feed(JSONLexer *lexer, const char *buffer,
size_t size)
for (i = 0; i < size; i++) {
int err;
- err = json_lexer_feed_char(lexer, buffer[i]);
+ err = json_lexer_feed_char(lexer, buffer[i], false);
if (err < 0) {
return err;
}
--
1.7.0.4
- [Qemu-devel] [PATCH v1][ 02/14] QError: Introduce qerror_format(), (continued)
- [Qemu-devel] [PATCH v1][ 02/14] QError: Introduce qerror_format(), Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 13/14] json-streamer: add handling for JSON_ERROR token/state, Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 10/14] json-lexer: reset the lexer state on an invalid token, Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 01/14] QError: Introduce qerror_format_desc(), Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 04/14] json-parser: propagate error from parser, Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 08/14] json-streamer: make sure to reset token_size after emitting a token list, Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 06/14] json-lexer: limit the maximum size of a given token, Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 07/14] json-streamer: limit the maximum recursion depth and maximum token count, Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 14/14] json-parser: add handling for NULL token list, Michael Roth, 2011/06/01
- [Qemu-devel] [PATCH v1][ 11/14] json-lexer: fix flushing logic to not always go to error state,
Michael Roth <=