From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#63535: Master branch: Error in forw_comment (syntax.c) handling of escaped LFs Date: Tue, 16 May 2023 14:03:18 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2901"; mail-complaints-to="usenet@ciao.gmane.io" Cc: acm@muc.de To: 63535@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue May 16 16:04:25 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pyvHt-0000XD-9R for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 16 May 2023 16:04:25 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyvHb-0002x5-DH; Tue, 16 May 2023 10:04:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyvHX-0002wo-Uu for bug-gnu-emacs@gnu.org; Tue, 16 May 2023 10:04:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pyvHW-0006vF-Jq for bug-gnu-emacs@gnu.org; Tue, 16 May 2023 10:04:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pyvHW-0008Sz-2C for bug-gnu-emacs@gnu.org; Tue, 16 May 2023 10:04:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 16 May 2023 14:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63535 X-GNU-PR-Package: emacs Original-Received: via spool by 63535-submit@debbugs.gnu.org id=B63535.168424581032500 (code B ref 63535); Tue, 16 May 2023 14:04:02 +0000 Original-Received: (at 63535) by debbugs.gnu.org; 16 May 2023 14:03:30 +0000 Original-Received: from localhost ([127.0.0.1]:46836 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pyvH0-0008S7-48 for submit@debbugs.gnu.org; Tue, 16 May 2023 10:03:30 -0400 Original-Received: from mx3.muc.de ([193.149.48.5]:36370) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pyvGw-0008Rr-07 for 63535@debbugs.gnu.org; Tue, 16 May 2023 10:03:28 -0400 Original-Received: (qmail 2285 invoked by uid 3782); 16 May 2023 16:03:19 +0200 Original-Received: from acm.muc.de (p4fe15025.dip0.t-ipconnect.de [79.225.80.37]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 16 May 2023 16:03:18 +0200 Original-Received: (qmail 30900 invoked by uid 1000); 16 May 2023 14:03:18 -0000 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:261784 Archived-At: On Tue, May 16, 2023 at 10:57:40 +0000, Alan Mackenzie wrote: > Hello, Emacs. > In the master branch: > Consider the following C++ Mode buffer: > // comment \ > comment line 2 > line_3(); > .. The backslash at the end of line 1 extends the comment into line 2. > Put point at // on L1, and do: > M-: (setq s (parse-partial-sexp (point) (+ (point) 9))) > .. s gets the parse state of the inside of the comment. > Now put point at EOL 1, between the backslash and the LF. Do > M-: (parse-partial-sexp (point) (point-max) nil nil s 'syntax-table) > .. This ought to leave point at BOL 2, since the syntax before the LF at > EOL 1 is that of a C++ comment, otherwise neutral. Instead, it leaves > point wrongly at BOL 3. > ######################################################################### > The reason for this bug is at L+42 of forw_comment (in syntax.c). There > we have > && !(comment_end_can_be_escaped && char_quoted (from, from_byte)) > .. Checking char_quoted is wrong. Instead the function should check the > current parse state. And here is a patch which fixes it. I will apply this patch to master soon if I don't hear any objection. diff --git a/src/syntax.c b/src/syntax.c index e9e04e2d638..76d9f16e4ed 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -2344,7 +2344,9 @@ forw_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, && SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0) == style && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ? (nesting > 0 && --nesting == 0) : nesting < 0) - && !(comment_end_can_be_escaped && char_quoted (from, from_byte))) + && !(comment_end_can_be_escaped && + (((prev_syntax & 0xff) == Sescape) + || ((prev_syntax & 0xff) == Scharquote)))) /* We have encountered a comment end of the same style as the comment sequence which began this comment section. */ -- Alan Mackenzie (Nuremberg, Germany).