|
|
9ae3a8 |
From c4c2e01b3fa861de40f809785a0643d56e2b311e Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
Date: Wed, 27 Jul 2016 07:35:03 +0200
|
|
|
9ae3a8 |
Subject: [PATCH 05/16] qjson: Spell out some silent assumptions
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1469604913-12442-7-git-send-email-armbru@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 71473
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.3 qemu-kvm PATCH v2 05/15] qjson: Spell out some silent assumptions
|
|
|
9ae3a8 |
Bugzilla: 1276036
|
|
|
9ae3a8 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
Message-Id: <1448486613-17634-5-git-send-email-armbru@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit b8d3b1da3cdbb02e180618d6be346c564723015d)
|
|
|
9ae3a8 |
Signed-off-by: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
include/qapi/qmp/json-lexer.h | 3 ++-
|
|
|
9ae3a8 |
qobject/json-lexer.c | 7 ++++++-
|
|
|
9ae3a8 |
2 files changed, 8 insertions(+), 2 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/include/qapi/qmp/json-lexer.h b/include/qapi/qmp/json-lexer.h
|
|
|
9ae3a8 |
index cdff046..61a143f 100644
|
|
|
9ae3a8 |
--- a/include/qapi/qmp/json-lexer.h
|
|
|
9ae3a8 |
+++ b/include/qapi/qmp/json-lexer.h
|
|
|
9ae3a8 |
@@ -18,7 +18,8 @@
|
|
|
9ae3a8 |
#include "qapi/qmp/qlist.h"
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
typedef enum json_token_type {
|
|
|
9ae3a8 |
- JSON_OPERATOR = 100,
|
|
|
9ae3a8 |
+ JSON_MIN = 100,
|
|
|
9ae3a8 |
+ JSON_OPERATOR = JSON_MIN,
|
|
|
9ae3a8 |
JSON_INTEGER,
|
|
|
9ae3a8 |
JSON_FLOAT,
|
|
|
9ae3a8 |
JSON_KEYWORD,
|
|
|
9ae3a8 |
diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c
|
|
|
9ae3a8 |
index 440df60..f106ffb 100644
|
|
|
9ae3a8 |
--- a/qobject/json-lexer.c
|
|
|
9ae3a8 |
+++ b/qobject/json-lexer.c
|
|
|
9ae3a8 |
@@ -30,7 +30,7 @@
|
|
|
9ae3a8 |
*/
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
enum json_lexer_state {
|
|
|
9ae3a8 |
- IN_ERROR = 0,
|
|
|
9ae3a8 |
+ IN_ERROR = 0, /* must really be 0, see json_lexer[] */
|
|
|
9ae3a8 |
IN_DQ_UCODE3,
|
|
|
9ae3a8 |
IN_DQ_UCODE2,
|
|
|
9ae3a8 |
IN_DQ_UCODE1,
|
|
|
9ae3a8 |
@@ -62,6 +62,8 @@ enum json_lexer_state {
|
|
|
9ae3a8 |
IN_START,
|
|
|
9ae3a8 |
};
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+QEMU_BUILD_BUG_ON((int)JSON_MIN <= (int)IN_START);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
#define TERMINAL(state) [0 ... 0x7F] = (state)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* Return whether TERMINAL is a terminal state and the transition to it
|
|
|
9ae3a8 |
@@ -71,6 +73,8 @@ enum json_lexer_state {
|
|
|
9ae3a8 |
(json_lexer[(old_state)][0] == (terminal))
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static const uint8_t json_lexer[][256] = {
|
|
|
9ae3a8 |
+ /* Relies on default initialization to IN_ERROR! */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
/* double quote string */
|
|
|
9ae3a8 |
[IN_DQ_UCODE3] = {
|
|
|
9ae3a8 |
['0' ... '9'] = IN_DQ_STRING,
|
|
|
9ae3a8 |
@@ -287,6 +291,7 @@ static int json_lexer_feed_char(JSONLexer *lexer, char ch, bool flush)
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
do {
|
|
|
9ae3a8 |
+ assert(lexer->state <= ARRAY_SIZE(json_lexer));
|
|
|
9ae3a8 |
new_state = json_lexer[lexer->state][(uint8_t)ch];
|
|
|
9ae3a8 |
char_consumed = !TERMINAL_NEEDED_LOOKAHEAD(lexer->state, new_state);
|
|
|
9ae3a8 |
if (char_consumed) {
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.8.3.1
|
|
|
9ae3a8 |
|