[PATCH 06/10] emacs: Fix bug in resynchronizing after a JSON parse error

Mark Walters markwalters1009 at gmail.com
Sat Dec 8 00:32:54 PST 2012


This patch looks good to me. Should it go in ahead of the rest of the
series as it essentially a bugfix?

Best wishes

Mark

On Sun, 02 Dec 2012, Austin Clements <amdragon at MIT.EDU> wrote:
> 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
>
> _______________________________________________
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch


More information about the notmuch mailing list