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: Mon, 22 May 2023 14:59:32 +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="17617"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 63535@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon May 22 17:00:12 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 1q171A-0004My-AN for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 22 May 2023 17:00:12 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q1713-00022r-Kz; Mon, 22 May 2023 11:00:05 -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 1q1710-00022F-VU for bug-gnu-emacs@gnu.org; Mon, 22 May 2023 11:00:03 -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 1q1710-0002DI-Lw for bug-gnu-emacs@gnu.org; Mon, 22 May 2023 11:00:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q1710-0003zy-HG for bug-gnu-emacs@gnu.org; Mon, 22 May 2023 11:00: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: Mon, 22 May 2023 15:00: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.168476758515319 (code B ref 63535); Mon, 22 May 2023 15:00:02 +0000 Original-Received: (at 63535) by debbugs.gnu.org; 22 May 2023 14:59:45 +0000 Original-Received: from localhost ([127.0.0.1]:35753 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q170i-0003yz-Sv for submit@debbugs.gnu.org; Mon, 22 May 2023 10:59:45 -0400 Original-Received: from mx3.muc.de ([193.149.48.5]:10125) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q170f-0003yg-FC for 63535@debbugs.gnu.org; Mon, 22 May 2023 10:59:43 -0400 Original-Received: (qmail 65795 invoked by uid 3782); 22 May 2023 16:59:33 +0200 Original-Received: from acm.muc.de (pd953ae2b.dip0.t-ipconnect.de [217.83.174.43]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Mon, 22 May 2023 16:59:32 +0200 Original-Received: (qmail 2836 invoked by uid 1000); 22 May 2023 14:59:32 -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:262160 Archived-At: Hello, Stefan. On Wed, May 17, 2023 at 18:01:32 -0400, Stefan Monnier wrote: > Hi Alan, [ .... ] > AFAIK this is your code, so you should know better, but AFAICT > `prev_syntax` is not updated in the loop, so it only reflects the syntax > before the beginning of the scanned text, rather than anything near `from`. > Are you sure this is right? Thanks, you are correct, the patch was not good. It turned out to be quite tricky to get working. As well as forw_comment, I had to amend scan_sexps_forward to make it return a quoted state to its caller when this happens at the limit of the scan. I think the following patch is better. Would you please have a look at it, in the hope I haven't made any other silly mistakes. Thanks! diff --git a/src/syntax.c b/src/syntax.c index e9e04e2d638..94b2ac2b591 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -2338,13 +2338,16 @@ forw_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, return 0; } c = FETCH_CHAR_AS_MULTIBYTE (from_byte); + prev_syntax = syntax; syntax = SYNTAX_WITH_FLAGS (c); code = syntax & 0xff; if (code == Sendcomment && 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. */ @@ -2368,7 +2371,11 @@ forw_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, inc_both (&from, &from_byte); UPDATE_SYNTAX_TABLE_FORWARD (from); if (from == stop) continue; /* Failure */ - } + c = FETCH_CHAR_AS_MULTIBYTE (from_byte); + prev_syntax = syntax; + syntax = Smax; + code = syntax; + } inc_both (&from, &from_byte); UPDATE_SYNTAX_TABLE_FORWARD (from); @@ -3349,7 +3356,14 @@ do { prev_from = from; \ are invalid now. Luckily, the `done' doesn't use them and the INC_FROM sets them to a sane value without looking at them. */ - if (!found) goto done; + if (!found) + { + if ((prev_from_syntax & 0xff) == Sescape + || (prev_from_syntax & 0xff) == Scharquote) + goto endquoted; + else + goto done; + } INC_FROM; state->incomment = 0; state->comstyle = 0; /* reset the comment style */ > Stefan -- Alan Mackenzie (Nuremberg, Germany).