From 8f9ab607b397678ffbffc4e3a5f063f439312e25 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 24 Nov 2019 11:47:31 -0800 Subject: listener: fix buggy balanced line check. * parser.c (is_balanced_line): When handling the closing characters, we must look for the state type which matches the character type, not state[sp]. Of course state[sp] == match, since we initialized it that way, and so state[sp] != match is always false. We want match to be derived from the character ch, not from state[sp]. Also, the polarity in the match-not-found return case is wrong; we must return 0. --- parser.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/parser.c b/parser.c index a0c51292..60d98df3 100644 --- a/parser.c +++ b/parser.c @@ -1155,12 +1155,17 @@ static int is_balanced_line(const wchar_t *line, void *ctx) break; case ')': case ']': case '}': { - enum state match = state[sp]; + enum state match = 0; + switch (ch) { + case ')': match = ST_PAR; break; + case ']': match = ST_BKT; break; + case '}': match = ST_BRC; break; + } while (sp > 0 && state[sp] != match) sp--; if (state[sp] != match) - return 1; + return 0; if (count[sp] == 0) sp--; else -- cgit v1.2.3