unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#5251: 23.1; problem in decode_eol of coding.c
@ 2009-12-20  8:57 Toru TSUNEYOSHI
  2016-02-17  3:41 ` Andrew Hyatt
  0 siblings, 1 reply; 6+ messages in thread
From: Toru TSUNEYOSHI @ 2009-12-20  8:57 UTC (permalink / raw)
  To: bug-gnu-emacs

[-- Attachment #1: Type: Text/Plain, Size: 1008 bytes --]

In GNU Emacs 23.1, there is a problem in decode_eol of coding.c.

In buffer of which enable-multibyte-characters is nil,
the function `decode-coding-region' should delete the character '^M'
(code: 0x0d) at the end of line,
in case that the function parameter `coding-system' is *-dos (and
the variable `inhibit-eol-conversion' is nil).
But, in practice, the function doesn't delete all of the character '^M'.

You can watch the problem with the following.

========================================================================
(progn
  (pop-to-buffer (generate-new-buffer-name "*scratch*"))
  (set-buffer-multibyte nil)
  (insert (encode-coding-string "あ" 'euc-jp) "\xd" "\n")
  (read-char "(press any key)")
  (decode-coding-region (point-min) (point-max) 'euc-jp-dos)
  (read-char "doesn't delete all of the character '^M'. (press any key)")
  (set-buffer-multibyte t))
========================================================================

I made a patch to fix the problem. Please check it.

[-- Attachment #2: coding.c__decode_eol.diff --]
[-- Type: Text/X-Patch, Size: 395 bytes --]

--- coding.c.orig	2009-07-08 12:09:16.000000000 +0900
+++ coding.c	2009-12-20 16:36:45.887121600 +0900
@@ -6598,7 +6598,8 @@
 	{
 	  int pos_byte = coding->dst_pos_byte;
 	  int pos = coding->dst_pos;
-	  int pos_end = pos + coding->produced_char - 1;
+	  int pos_end = pos + (coding->dst_multibyte
+			       ? coding->produced_char : coding->produced) - 1;
 
 	  while (pos < pos_end)
 	    {

^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#5251: 23.1; problem in decode_eol of coding.c
  2009-12-20  8:57 bug#5251: 23.1; problem in decode_eol of coding.c Toru TSUNEYOSHI
@ 2016-02-17  3:41 ` Andrew Hyatt
  2016-02-17 15:53   ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Hyatt @ 2016-02-17  3:41 UTC (permalink / raw)
  To: Toru TSUNEYOSHI; +Cc: 5251


I can verify that this issue still happens in Emacs 25.  This simple fix
seems to have slipped by unnoticed many years ago, hopefully someone
that is qualified to comment on the patch will see it now.

BTW, this seems like a nice thing to unit test with ert, if a fix does
take place.

Toru TSUNEYOSHI <t_tuneyosi@hotmail.com> writes:

> In GNU Emacs 23.1, there is a problem in decode_eol of coding.c.
>
> In buffer of which enable-multibyte-characters is nil,
> the function `decode-coding-region' should delete the character '^M'
> (code: 0x0d) at the end of line,
> in case that the function parameter `coding-system' is *-dos (and
> the variable `inhibit-eol-conversion' is nil).
> But, in practice, the function doesn't delete all of the character '^M'.
>
> You can watch the problem with the following.
>
> ========================================================================
> (progn
>   (pop-to-buffer (generate-new-buffer-name "*scratch*"))
>   (set-buffer-multibyte nil)
>   (insert (encode-coding-string "あ" 'euc-jp) "\xd" "\n")
>   (read-char "(press any key)")
>   (decode-coding-region (point-min) (point-max) 'euc-jp-dos)
>   (read-char "doesn't delete all of the character '^M'. (press any key)")
>   (set-buffer-multibyte t))
> ========================================================================
>
> I made a patch to fix the problem. Please check it.
>
> --- coding.c.orig	2009-07-08 12:09:16.000000000 +0900
> +++ coding.c	2009-12-20 16:36:45.887121600 +0900
> @@ -6598,7 +6598,8 @@
>  	{
>  	  int pos_byte = coding->dst_pos_byte;
>  	  int pos = coding->dst_pos;
> -	  int pos_end = pos + coding->produced_char - 1;
> +	  int pos_end = pos + (coding->dst_multibyte
> +			       ? coding->produced_char : coding->produced) - 1;
>  
>  	  while (pos < pos_end)
>  	    {





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#5251: 23.1; problem in decode_eol of coding.c
  2016-02-17  3:41 ` Andrew Hyatt
@ 2016-02-17 15:53   ` Eli Zaretskii
  2016-02-17 17:03     ` Toru TSUNEYOSHI
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2016-02-17 15:53 UTC (permalink / raw)
  To: Andrew Hyatt; +Cc: t_tuneyosi, 5251-done

> From: Andrew Hyatt <ahyatt@gmail.com>
> Date: Tue, 16 Feb 2016 22:41:32 -0500
> Cc: 5251@debbugs.gnu.org
> 
> 
> I can verify that this issue still happens in Emacs 25.  This simple fix
> seems to have slipped by unnoticed many years ago, hopefully someone
> that is qualified to comment on the patch will see it now.

Thanks for the reminder, I fixed this now on the emacs-25 branch.
(The proposed patch was not entirely correct, although it was in the
right direction, and happened to fix this particular case.)

It is indeed a shame that such a simple bug was left unresolved for
such a long time, but better late than never.

> BTW, this seems like a nice thing to unit test with ert, if a fix does
> take place.

Yes, that would be very welcome, thanks.  Looks like coding-tests.el
is a good place to add such a test.  Please be sure to include lone ^M
characters, as well as those followed by a newline, so that we are
sure lone CRs are not removed.

Thanks.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#5251: 23.1; problem in decode_eol of coding.c
  2016-02-17 15:53   ` Eli Zaretskii
@ 2016-02-17 17:03     ` Toru TSUNEYOSHI
  2016-02-17 19:24       ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Toru TSUNEYOSHI @ 2016-02-17 17:03 UTC (permalink / raw)
  To: eliz; +Cc: ahyatt, 5251-done

Oh, I have forgotten this issue completely. :-)

From: Andrew Hyatt <ahyatt@gmail.com>
Subject: Re: bug#5251: 23.1; problem in decode_eol of coding.c
Date: Tue, 16 Feb 2016 22:41:32 -0500
Message-ID: <m2bn7gypeb.fsf@gmail.com>

> BTW, this seems like a nice thing to unit test with ert, if a fix does
> take place.

What is the word "ert" ? Would you like to tell me the meaning ?

From: Eli Zaretskii <eliz@gnu.org>
Subject: Re: bug#5251: 23.1; problem in decode_eol of coding.c
Date: Wed, 17 Feb 2016 17:53:41 +0200
Message-ID: <8337srwcxm.fsf@gnu.org>

> Thanks for the reminder, I fixed this now on the emacs-25 branch.
> (The proposed patch was not entirely correct, although it was in the
> right direction, and happened to fix this particular case.)

After I checked my patch again, I thoght my patch was not enough maybe.

> better late than never.

Yes, that's right.

Thanks, Mr. Andrew Hyatt and Mr. Eli Zaretskii.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#5251: 23.1; problem in decode_eol of coding.c
  2016-02-17 17:03     ` Toru TSUNEYOSHI
@ 2016-02-17 19:24       ` Eli Zaretskii
  2016-02-18  2:56         ` Toru TSUNEYOSHI
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2016-02-17 19:24 UTC (permalink / raw)
  To: Toru TSUNEYOSHI; +Cc: ahyatt, 5251-done

> Date: Thu, 18 Feb 2016 02:03:08 +0900
> CC: ahyatt@gmail.com, 5251-done@debbugs.gnu.org
> From: Toru TSUNEYOSHI <t_tuneyosi@hotmail.com>
> 
> What is the word "ert" ? Would you like to tell me the meaning ?

Emacs Regression Test suite.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#5251: 23.1; problem in decode_eol of coding.c
  2016-02-17 19:24       ` Eli Zaretskii
@ 2016-02-18  2:56         ` Toru TSUNEYOSHI
  0 siblings, 0 replies; 6+ messages in thread
From: Toru TSUNEYOSHI @ 2016-02-18  2:56 UTC (permalink / raw)
  To: eliz; +Cc: ahyatt, 5251-done

From: Eli Zaretskii <eliz@gnu.org>
Subject: Re: bug#5251: 23.1; problem in decode_eol of coding.c
Date: Wed, 17 Feb 2016 21:24:23 +0200
Message-ID: <83mvqzuom0.fsf@gnu.org>

> Emacs Regression Test suite.

I don't know it at all.
Thanks.





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-02-18  2:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-20  8:57 bug#5251: 23.1; problem in decode_eol of coding.c Toru TSUNEYOSHI
2016-02-17  3:41 ` Andrew Hyatt
2016-02-17 15:53   ` Eli Zaretskii
2016-02-17 17:03     ` Toru TSUNEYOSHI
2016-02-17 19:24       ` Eli Zaretskii
2016-02-18  2:56         ` Toru TSUNEYOSHI

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).