all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kazuhiro Ito <kzhr@d1.dion.ne.jp>
To: 9389@debbugs.gnu.org
Subject: bug#9389: 23.3.50; unencodable-char-position has buffer relocation problem
Date: Sun, 28 Aug 2011 09:07:25 +0900	[thread overview]
Message-ID: <20110828000802.B9D1B34803A@msa103.auone-net.jp> (raw)

When I start precompiled Windows binary with -Q and evaluate below
code, I have unexpected result.

(with-temp-buffer
  (insert (make-string 16 ?A))
  (insert #x80)
  (unencodable-char-position 1 18 'ctext-unix))

-> 13 (Emacs 23.1)
-> 5  (Emacs 23.3)

If I evaluate it twice, it returns expected result (17).

I think the cause of the problem is similar to bug#9318.
unencodable-char-position uses char_charset(), which could cause a
relocation of buffes.  After using it, pointers must be updated as
needed.


=== modified file 'src/coding.c'
--- src/coding.c	2011-05-09 09:59:23 +0000
+++ src/coding.c	2011-08-27 04:29:23 +0000
@@ -8861,7 +8924,7 @@
   Lisp_Object attrs, charset_list, translation_table;
   Lisp_Object positions;
   int from, to;
-  const unsigned char *p, *stop, *pend;
+  const unsigned char *p, *stop, *pend, *orig;
   int ascii_compatible;
 
   setup_coding_system (Fcheck_coding_system (coding_system), &coding);
@@ -8881,7 +8944,7 @@
 	  || (ascii_compatible
 	      && (to - from) == (CHAR_TO_BYTE (to) - (CHAR_TO_BYTE (from)))))
 	return Qnil;
-      p = CHAR_POS_ADDR (from);
+      p = orig = CHAR_POS_ADDR (from);
       pend = CHAR_POS_ADDR (to);
       if (from < GPT && to >= GPT)
 	stop = GPT_ADDR;
@@ -8918,6 +8981,7 @@
   while (1)
     {
       int c;
+      struct charset *charset;
 
       if (ascii_compatible)
 	while (p < stop && ASCII_BYTE_P (*p))
@@ -8931,9 +8995,21 @@
 	}
 
       c = STRING_CHAR_ADVANCE (p);
+
+      charset_map_loaded = 0;
+      charset = char_charset (translate_char (translation_table, c),
+			      charset_list, NULL);
+      if (charset_map_loaded && NILP (string))
+	{
+	  EMACS_INT offset = CHAR_POS_ADDR (from) - orig;
+	  orig += offset;
+	  p += offset;
+	  pend += offset;
+	  stop += offset;
+	}
+
       if (! (ASCII_CHAR_P (c) && ascii_compatible)
-	  && ! char_charset (translate_char (translation_table, c),
-			     charset_list, NULL))
+	  && ! charset)
 	{
 	  positions = Fcons (make_number (from), positions);
 	  n--;

-- 
Kazuhiro Ito





             reply	other threads:[~2011-08-28  0:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-28  0:07 Kazuhiro Ito [this message]
2011-12-11 12:27 ` bug#9389: 23.3.50; unencodable-char-position has buffer relocation problem Kenichi Handa
2011-12-15 12:30   ` Kazuhiro Ito

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110828000802.B9D1B34803A@msa103.auone-net.jp \
    --to=kzhr@d1.dion.ne.jp \
    --cc=9389@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.