From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: handa Newsgroups: gmane.emacs.bugs Subject: bug#46933: Possible bugs in filepos-to-bufferpos / bufferpos-to-filepos Date: Sat, 27 Mar 2021 14:38:56 +0900 Message-ID: <874kgxtatr.fsf@gnu.org> References: <9cff0f8894f167925251@heytings.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18064"; mail-complaints-to="usenet@ciao.gmane.io" Cc: gregory@heytings.org, 46933@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Mar 27 06:40:10 2021 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 1lQ1gA-0004cW-RS for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 27 Mar 2021 06:40:10 +0100 Original-Received: from localhost ([::1]:38782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lQ1g9-00050R-Sn for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 27 Mar 2021 01:40:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60096) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lQ1g2-0004z6-MH for bug-gnu-emacs@gnu.org; Sat, 27 Mar 2021 01:40:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:59852) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lQ1g2-000398-8M for bug-gnu-emacs@gnu.org; Sat, 27 Mar 2021 01:40:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lQ1g2-0007Ku-3E for bug-gnu-emacs@gnu.org; Sat, 27 Mar 2021 01:40:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: handa Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 27 Mar 2021 05:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46933 X-GNU-PR-Package: emacs Original-Received: via spool by 46933-submit@debbugs.gnu.org id=B46933.161682354928138 (code B ref 46933); Sat, 27 Mar 2021 05:40:02 +0000 Original-Received: (at 46933) by debbugs.gnu.org; 27 Mar 2021 05:39:09 +0000 Original-Received: from localhost ([127.0.0.1]:43165 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lQ1fA-0007Jl-LY for submit@debbugs.gnu.org; Sat, 27 Mar 2021 01:39:08 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:38754) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lQ1f8-0007JL-Ku for 46933@debbugs.gnu.org; Sat, 27 Mar 2021 01:39:07 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:58000) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lQ1f3-0002dG-C9; Sat, 27 Mar 2021 01:39:01 -0400 Original-Received: from fl1-60-236-248-230.iba.mesh.ad.jp ([60.236.248.230]:52970 helo=shatin) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lQ1f2-0005us-EL; Sat, 27 Mar 2021 01:39:00 -0400 Original-Received: from handa by shatin with local (Exim 4.93) (envelope-from ) id 1lQ1ey-0004xJ-L4; Sat, 27 Mar 2021 14:38:56 +0900 In-Reply-To: <83ft0obk7i.fsf@gnu.org> (message from Eli Zaretskii on Sun, 21 Mar 2021 17:27:45 +0200) 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" Xref: news.gmane.io gmane.emacs.bugs:203095 Archived-At: In article <83ft0obk7i.fsf@gnu.org>, Eli Zaretskii writes: > Kenichi, why are these 6 bytes inserted by encode-coding-region, but > not when we encode the same text as part of saving the buffer to its > file? And why does it happen near the end of the text, between those > 2 particular letters? There surely exists a bug. Could you please try the attached patch? The reason why that bug did not happen on file writing is that the code in write_region calls encoding routine repeatedly without CODING_MODE_LAST_BLOCK flag, and only in the case that flushing is required (e.g. the case of iso-2022-jp), just for flushing, it calls enoding routine again with CODING_MODE_LAST_BLOCK flag. In that case, carryover does not happen in encode_coding (). --- K. Handa handa@gnu.org diff --git a/src/coding.c b/src/coding.c index 221a9cad89..a9d5a7ccdc 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7799,7 +7799,14 @@ encode_coding (struct coding_system *coding) coding_set_source (coding); consume_chars (coding, translation_table, max_lookup); coding_set_destination (coding); + /* If consume_chars did not consume all source chars, we call + coding->encoder again in the next iteration, and thus, for this + iteration, we must clear CODING_MODE_LAST_BLOCK flag. */ + unsigned saved_mode = coding->mode; + if (coding->consumed_char < coding->src_chars) + coding->mode &= ~CODING_MODE_LAST_BLOCK; (*(coding->encoder)) (coding); + coding->mode = saved_mode; } while (coding->consumed_char < coding->src_chars); if (BUFFERP (coding->dst_object) && coding->produced_char > 0)