Received: from eggs.gnu.org ([2001:4830:134:3::10]:51202) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fuKqb-00014o-1p for qemu-devel@nongnu.org; Mon, 27 Aug 2018 12:58:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fuKqW-0005nC-Kx for qemu-devel@nongnu.org; Mon, 27 Aug 2018 12:58:36 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55980 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fuKqW-0005m6-8P for qemu-devel@nongnu.org; Mon, 27 Aug 2018 12:58:32 -0400 References: <20180827070021.11931-1-armbru@redhat.com> <20180827070021.11931-3-armbru@redhat.com> From: Eric Blake Message-ID: Date: Mon, 27 Aug 2018 11:58:28 -0500 MIME-Version: 1.0 In-Reply-To: <20180827070021.11931-3-armbru@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/6] json: Clean up how lexer consumes "end of input" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster , qemu-devel@nongnu.org Cc: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com On 08/27/2018 02:00 AM, Markus Armbruster wrote: > When the lexer isn't in its start state at the end of input, it's > working on a token. To flush it out, it needs to transit to its start > state on "end of input" lookahead. > > There are two ways to the start state, depending on the current state: > > * If the lexer is in a TERMINAL(JSON_FOO) state, it can emit a > JSON_FOO token. > > * Else, it can go to IN_ERROR state, and emit a JSON_ERROR token. > > There are complications, however: > > * The transition to IN_ERROR state consumes the input character and > adds it to the JSON_ERROR token. The latter is inappropriate for > the "end of input" character, so we suppress that. See also recent > commit "json: Fix lexer to include the bad character in JSON_ERROR > token". Now commit a2ec6be7 > > * The transition to a TERMINAL(JSON_FOO) state doesn't consume the > input character. In that case, the lexer normally loops until it is > consumed. We have to suppress that for the "end of input" input > character. If we didn't, the lexer would consume it by entering > IN_ERROR state, emitting a bogus JSON_ERROR token. We fixed that in > commit bd3924a33a6. > > However, simply breaking the loop this way assumes that the lexer > needs exactly one state transition to reach its start state. That > assumption is correct now, but it's unclean, and I'll soon break it. > Clean up: instead of breaking the loop after one iteration, break it > after it reached the start state. > > Signed-off-by: Markus Armbruster > --- > qobject/json-lexer.c | 17 +++++++++-------- > 1 file changed, 9 insertions(+), 8 deletions(-) > > diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c > index 4867839f66..ec3aec726f 100644 > --- a/qobject/json-lexer.c > +++ b/qobject/json-lexer.c > @@ -261,7 +261,8 @@ void json_lexer_init(JSONLexer *lexer, bool enable_interpolation) > > static void json_lexer_feed_char(JSONLexer *lexer, char ch, bool flush) > { > - int char_consumed, new_state; > + int new_state; > + bool char_consumed = false; Yay for the switch to bool. Reviewed-by: Eric Blake -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org