Subject: Re: bug#9318: 23.3.50; The first call of encode-coding-region() returns wrong result

From: Kazuhiro Ito <[email-masked]>
Date: Wed, 24 Aug 2011 18:37:24 +0900

> I built Emacs 23.3 with "-O0 -g" option on NetBSD 5.1 (amd64), and
> started with below commad (via SSH).
> 
> gdb --args emacs -Q --no-splash
> 
> Next, inputtedand below code and evaluated with C-x C-e.
> 
> (progn
>   (goto-char (point-min))
>   (insert #x80)
>   (insert (make-string 16 ?A))
>   (encode-coding-region 1 18 'ctext-unix))
> 
> backtrace is below.  Please let me know if you need more information.
> 
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x0000000000557419 in mark_object (arg=4702111234474983745) at alloc.c:5473
> 5473            if (STRING_MARKED_P (ptr))

I think relocation of buffer may cause the problem.

The comment for CODING_DECODE_CHAR macro in coding.c says as below.

> /* This wrapper macro is used to preserve validity of pointers into
>    buffer text across calls to decode_char, which could cause
>    relocation of buffers if it loads a charset map, because loading a
>    charset map allocates large structures.  */

encode_coding_iso_2022() uses ENCODE_ISO_CHARACTER macro, which uses
ENCODE_CHAR macro.  ENCODE_CHAR macro calls encode_char() and it may
load a charset map.  If this is the cause of the problem,
encode_coding_emace_mule() has the same problem.

-- 
Kazuhiro Ito