Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 26198431FAF for ; Sat, 1 Dec 2012 18:40:35 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FFJERYebJdiz for ; Sat, 1 Dec 2012 18:40:33 -0800 (PST) Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU [18.9.25.15]) by olra.theworths.org (Postfix) with ESMTP id 1F26F429E3B for ; Sat, 1 Dec 2012 18:40:22 -0800 (PST) X-AuditID: 1209190f-b7fec6d00000090d-9b-50babf96250a Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP id 50.06.02317.69FBAB05; Sat, 1 Dec 2012 21:40:22 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id qB22eC44019892; Sat, 1 Dec 2012 21:40:12 -0500 Received: from drake.dyndns.org (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qB22e6rt025600 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 1 Dec 2012 21:40:10 -0500 (EST) Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1TezTS-0000xe-0h; Sat, 01 Dec 2012 21:40:06 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 06/10] emacs: Fix bug in resynchronizing after a JSON parse error Date: Sat, 1 Dec 2012 21:39:58 -0500 Message-Id: <1354416002-3557-6-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1354416002-3557-1-git-send-email-amdragon@mit.edu> References: <1354416002-3557-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixG6nojtt/64Ag0nnZC2u35zJ7MDo8WzV LeYAxigum5TUnMyy1CJ9uwSujJ+LPzIXHBOoWL3iFmMD4wbeLkZODgkBE4l/b7tYIWwxiQv3 1rN1MXJxCAnsY5SY+6+fFcJZzyix4cIxZpAqIYGHTBJLDxdCJOYySnxc/QIswSagIbFt/3JG EFtEQFpi593ZQN0cHMwCahJ/ulRAwsICgRIrVz4F28YioCpxdeZvsFZeAXuJC03zGSGuUJTo fjaBDaSVU8BBYkU3D8Rae4n/v6+xTWDkX8DIsIpRNiW3Sjc3MTOnODVZtzg5MS8vtUjXRC83 s0QvNaV0EyMoZDgl+XcwfjuodIhRgINRiYeXcdauACHWxLLiytxDjJIcTEqivFd2AIX4kvJT KjMSizPii0pzUosPMUpwMCuJ8LKYAOV4UxIrq1KL8mFS0hwsSuK8V1Nu+gsJpCeWpGanphak FsFkZTg4lCR4q/cBNQoWpaanVqRl5pQgpJk4OEGG8wANf7QXZHhxQWJucWY6RP4Uo6KUOO81 kIQASCKjNA+uFxbTrxjFgV4R5vUEWcEDTAdw3a+ABjMBDX6zbDvI4JJEhJRUA+PE/IqwG8wH jIzyjGs63/hW1m+2Z1+Zc4rVLquH89fLJRNPcigsqV52uZ75C7fqyjNGkZ+utBZXna5a7cFv qXdv6oScNek38yd7evALf6y+K/FmZfTEBWbOgXd/257nZRPO2NGQwvp2V5PVpTMHsxvDrznX 5NmvvdD+IfuUv5X7hqU/Nxq/UFdiKc5INNRiLipOBAAkaR7vxAIAAA== X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Dec 2012 02:40:35 -0000 Previously, if the input stream consisted only of an error message, notmuch-json-begin-compound would signal a (wrong-type-argument number-or-marker-p nil) error when reaching the end of the error message. This happened because notmuch-json-scan-to-value would think that it reached a value and put the parser into the 'value state. Even after notmuch-json-begin-compound signaled the syntax error, the parser would remain in this state and when the resynchronization logic reached the end of the buffer, the parser would fail because the 'value state indicates that characters are available. This fixes this problem by restoring the parser's previous state if it encounters a syntax error. --- emacs/notmuch-lib.el | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 1d0ec17..9402456 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -474,15 +474,19 @@ Entering JSON objects is currently unimplemented." (with-current-buffer (notmuch-json-buffer jp) ;; Disallow terminators (setf (notmuch-json-allow-term jp) nil) - (or (notmuch-json-scan-to-value jp) - (if (/= (char-after) ?\[) - (signal 'json-readtable-error (list "expected '['")) - (forward-char) - (push ?\] (notmuch-json-term-stack jp)) - ;; Expect a value or terminator next - (setf (notmuch-json-next jp) 'expect-value - (notmuch-json-allow-term jp) t) - t)))) + ;; Save "next" so we can restore it if there's a syntax error + (let ((saved-next (notmuch-json-next jp))) + (or (notmuch-json-scan-to-value jp) + (if (/= (char-after) ?\[) + (progn + (setf (notmuch-json-next jp) saved-next) + (signal 'json-readtable-error (list "expected '['"))) + (forward-char) + (push ?\] (notmuch-json-term-stack jp)) + ;; Expect a value or terminator next + (setf (notmuch-json-next jp) 'expect-value + (notmuch-json-allow-term jp) t) + t))))) (defun notmuch-json-read (jp) "Parse the value at point in JP's buffer. -- 1.7.10.4