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