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

From: Kazuhiro Ito <[email-masked]>
Date: Sun, 21 Aug 2011 09:17:05 +0900

> >> When I start Emacs and evaluate the below code, unexpected result returns.
> >
> >> (let ((func (lambda ()
> >> 	      (with-temp-buffer
> >> 		(mapc 'insert '(166 25339))
> >> 		(encode-coding-region (point-min) (point-max) 'ctext-unix)
> >> 		(buffer-string)))))
> >>   (cons (funcall func)
> >> 	(funcall func)))
> >> -> ("¦拻^@^@^@^@^@^@^@^@^@^@" . "^[$(D\"C^[$(H*f^[(B")
> >
> > I noticed this problem is not Windows specific.  I confirmed that it
> > is reproducible in Emacs 23.3.1 (build by pkgsrc) on NetBSD/amd64 via
> > SSH from remote host.  But it doesn't occur on openSUSE 11.3.
> 
> Could you run Emacs under a debugger, trigger the crash, and provide a
> backtrace?  (You will need to have compiled Emacs with debugging
> symbols.)

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))
(gdb) bt full
#0  0x0000000000557419 in mark_object (arg=4702111234474983745) at alloc.c:5473
        ptr = (struct Lisp_String *) 0x4141414141414140
        obj = 4702111234474983745
        cdr_count = 0
#1  0x0000000000557320 in mark_char_table (ptr=0x1281800) at alloc.c:5405
        val = 4702111234474983745
        size = 130
        i = 0
#2  0x0000000000557315 in mark_char_table (ptr=0x17f6c00) at alloc.c:5402
        val = 19404805
        size = 34
        i = 14
#3  0x0000000000557315 in mark_char_table (ptr=0x13ea700) at alloc.c:5402
        val = 25127941
        size = 18
        i = 6
#4  0x0000000000557315 in mark_char_table (ptr=0x10ba800) at alloc.c:5402
        val = 20883205
        size = 68
        i = 4
#5  0x0000000000557838 in mark_object (arg=17541125) at alloc.c:5567
        obj = 17541125
        cdr_count = 0
#6  0x0000000000557228 in mark_vectorlike (ptr=0xb16480) at alloc.c:5377
        size = 10
        i = 9
#7  0x0000000000557855 in mark_object (arg=11625605) at alloc.c:5569
        obj = 11625605
        cdr_count = 0
#8  0x0000000000557228 in mark_vectorlike (ptr=0xb56000) at alloc.c:5377
        size = 434
        i = 107
#9  0x0000000000557855 in mark_object (arg=11886597) at alloc.c:5569
        obj = 11886597
        cdr_count = 0
#10 0x00000000005577b0 in mark_object (arg=10786565) at alloc.c:5562
        h = (struct Lisp_Hash_Table *) 0xa49700
        obj = 10786565
        cdr_count = 0
#11 0x00000000005568ff in Fgarbage_collect () at alloc.c:5092
        bind = (struct specbinding *) 0xb96526
        catch = (struct catchtag *) 0x7f7fffffc508
        handler = (struct handler *) 0x10
        stack_top_variable = 0 '\0'
        i = 418
        message_p = 0
        total = {140187732526192, 140187732526008, 140187732526000, 4294967295, 
  12148454, 10960258, 10312685, 68}
        count = 8
        t1 = {
  tv_sec = 1313842937, 
  tv_usec = 498976
}
        t2 = {
  tv_sec = 0, 
  tv_usec = 140187732530104
}
        t3 = {
  tv_sec = 11465618, 
  tv_usec = 0
}
#12 0x0000000000577bb4 in Ffuncall (nargs=2, args=0x7f7fffffc4f0) at eval.c:2965
        fun = 10313885
        original_fun = 10959186
        funcar = 10762338
        numargs = 1
        lisp_numargs = 10950075
        val = 68
        backtrace = {
  next = 0x7f7fffffc9a0, 
  function = 0x7f7fffffc4f8, 
  args = 0x7f7fffffc500, 
  nargs = 1, 
  evalargs = 0 '\0', 
  debug_on_exit = 0 '\0'
}
        internal_args = (Lisp_Object *) 0x7f7fffffc500
        i = 0
#13 0x00000000005ce3c1 in Fbyte_code (bytestr=9300689, vector=9300725, maxdepth=12)
    at bytecode.c:680
        count = 7
        op = 1
        vectorp = (Lisp_Object *) 0x8deb00
        bytestr_length = 18
        stack = {
  pc = 0x96972f ")\207", 
  top = 0x7f7fffffc4f8, 
  bottom = 0x7f7fffffc4f0, 
  byte_string = 9300689, 
  byte_string_start = 0x96971f "\b\203\b", 
  constants = 9300725, 
  next = 0x7f7fffffcb40
}
        top = (Lisp_Object *) 0x7f7fffffc4f0
        result = 10956883
#14 0x00000000005788cc in funcall_lambda (fun=9300621, nargs=1, 
    arg_vector=0x7f7fffffca28) at eval.c:3220
        val = 10762242
        syms_left = 10762242
        next = 18577650
        count = 6
        i = 1
        optional = 0
        rest = 0
#15 0x000000000057821a in Ffuncall (nargs=2, args=0x7f7fffffca20) at eval.c:3077
        fun = 9300621
        original_fun = 18577602
        funcar = 18577842
        numargs = 1
        lisp_numargs = 10956963
        val = 10762242
        backtrace = {
  next = 0x7f7fffffced0, 
  function = 0x7f7fffffca20, 
  args = 0x7f7fffffca28, 
  nargs = 1, 
  evalargs = 0 '\0', 
  debug_on_exit = 0 '\0'
}
        internal_args = (Lisp_Object *) 0xa730a3
        i = 0
#16 0x00000000005ce3c1 in Fbyte_code (bytestr=9301185, vector=9301221, maxdepth=12)
    at bytecode.c:680
        count = 5
        op = 1
        vectorp = (Lisp_Object *) 0x8decf0
        bytestr_length = 31
        stack = {
  pc = 0x969692 "\v)B\211\034A\n=\204\033", 
  top = 0x7f7fffffca28, 
  bottom = 0x7f7fffffca20, 
  byte_string = 9301185, 
  byte_string_start = 0x969685 "\b\204\b", 
  constants = 9301221, 
  next = 0x0
}
        top = (Lisp_Object *) 0x7f7fffffca20
        result = 10762242
#17 0x00000000005788cc in funcall_lambda (fun=9301109, nargs=1, 
    arg_vector=0x7f7fffffcfa8) at eval.c:3220
        val = 140187732528832
        syms_left = 10762242
        next = 18577650
        count = 4
        i = 1
        optional = 0
        rest = 0
#18 0x000000000057821a in Ffuncall (nargs=2, args=0x7f7fffffcfa0) at eval.c:3077
        fun = 9301109
        original_fun = 11438610
        funcar = 5059672
        numargs = 1
        lisp_numargs = 5059670
        val = 10762242
        backtrace = {
  next = 0x7f7fffffd310, 
  function = 0x7f7fffffcfa0, 
  args = 0x7f7fffffcfa8, 
  nargs = 1, 
  evalargs = 0 '\0', 
  debug_on_exit = 0 '\0'
}
        internal_args = (Lisp_Object *) 0xa77993
        i = 0
#19 0x000000000057296b in Fcall_interactively (function=11438610, 
    record_flag=10762242, keys=10790405) at callint.c:869
        val = 4
        args = (Lisp_Object *) 0x7f7fffffcfa0
        visargs = (Lisp_Object *) 0x7f7fffffcf80
        specs = 9301281
        filter_specs = 9301281
        teml = 5734938
        up_event = 10762242
        enable = 10762242
        speccount = 2
        next_event = 2
        prefix_arg = 10762242
        string = (unsigned char *) 0x7f7fffffcfc0 "P"
        tem = (unsigned char *) 0x61652c ""
        varies = (int *) 0x7f7fffffcf60
        i = 2
        j = 1
        count = 1
        foo = 1
        prompt1 = '\0' <repeats 99 times>
        tem1 = 0x0
        arg_from_tty = 0
        gcpro1 = {
  next = 0xa43802, 
  var = 0xa43802, 
  nvars = 0
}
        gcpro2 = {
  next = 0xa53bc2, 
  var = 0xa51c05, 
  nvars = 10828738
}
        gcpro3 = {
  next = 0xa55952, 
  var = 0xa53bc2, 
  nvars = 2
}
        gcpro4 = {
  next = 0xa43802, 
  var = 0xb4a776, 
  nvars = 2
}
        gcpro5 = {
  next = 0xa43802, 
  var = 0xa43802, 
  nvars = 10836306
}
        key_count = 2
        record_then_fail = 0
        save_this_command = 11438610
        save_last_command = 11490098
        save_this_original_command = 11438610
        save_real_this_command = 11438610
#20 0x0000000000577f70 in Ffuncall (nargs=4, args=0x7f7fffffd3b0) at eval.c:3037
        fun = 10312397
        original_fun = 10978002
        funcar = 4294967297
        numargs = 3
        lisp_numargs = 10937344
        val = 315
        backtrace = {
  next = 0x0, 
  function = 0x7f7fffffd3b0, 
  args = 0x7f7fffffd3b8, 
  nargs = 3, 
  evalargs = 0 '\0', 
  debug_on_exit = 0 '\0'
}
        internal_args = (Lisp_Object *) 0x7f7fffffd3b8
        i = 0
#21 0x000000000057795d in call3 (fn=10978002, arg1=11438610, arg2=10762242, 
    arg3=10762242) at eval.c:2857
        ret_ungc_val = 9301109
        gcpro1 = {
  next = 0x8dec75, 
  var = 0xa43802, 
  nvars = 4
}
        args = {10978002, 11438610, 10762242, 10762242}
#22 0x00000000004e4bca in Fcommand_execute (cmd=11438610, record_flag=10762242, 
    keys=10762242, special=10762242) at keyboard.c:10562
        final = 9301109
        tem = 10762242
        prefixarg = 10762242
#23 0x00000000004d564d in command_loop_1 () at keyboard.c:1906
        cmd = 11438610
        lose = 1
        keybuf = {96, 20, 8, 0, 140187732530800, 18451712, 1893, 0, 
  140187732530816, 1983, 18451712, 4294967317, 140187732530800, 6299742, 10656928, 
  216, 10937344, 7378697632079252736, 140187732530864, 9720, 274877896416, 
  140187732531032, 0, 140187732530872, 140187732530384, 0, 10762242, 12348018, 
  8166853, 10762242}
        i = 2
        prev_modiff = 158
        prev_buffer = (struct buffer *) 0xa51c00
        already_adjusted = 0
#24 0x0000000000575049 in internal_condition_case (bfun=0x4d3a17 <command_loop_1>, 
    handlers=10851522, hfun=0x4d34bc <cmd_error>) at eval.c:1492
        val = 10762242
        c = {
  tag = 10762242, 
  val = 10762242, 
  next = 0x7f7fffffd880, 
  gcpro = 0x0, 
  jmp = {2129, 140187732531264, 140187732541408, 140187698962432, 140187696909296, 
    3, 140187732531000, 5722036, 0, 140187732531488, 18636288}, 
  backlist = 0x0, 
  handlerlist = 0x0, 
  lisp_eval_depth = 0, 
  pdlcount = 2, 
  poll_suppress_count = 0, 
  interrupt_input_blocked = 0, 
  byte_stack = 0x0
}
        h = {
  handler = 10851522, 
  var = 10762242, 
  chosen_clause = 0, 
  tag = 0x7f7fffffd790, 
  next = 0x0
}
#25 0x00000000004d389f in command_loop_2 () at keyboard.c:1362
        val = 1
#26 0x0000000000574a0e in internal_catch (tag=10846786, 
    func=0x4d3885 <command_loop_2>, arg=10762242) at eval.c:1228
        c = {
  tag = 10846786, 
  val = 10762242, 
  next = 0x0, 
  gcpro = 0x0, 
  jmp = {2129, 140187732531488, 140187732541408, 140187698962432, 140187696909296, 
    3, 140187732531288, 5720565, 4301358603, 10820608, 11046651}, 
  backlist = 0x0, 
  handlerlist = 0x0, 
  lisp_eval_depth = 0, 
  pdlcount = 2, 
  poll_suppress_count = 0, 
  interrupt_input_blocked = 0, 
  byte_stack = 0x0
}
#27 0x00000000004d3859 in command_loop () at keyboard.c:1341
No locals.
#28 0x00000000004d3004 in recursive_edit_1 () at keyboard.c:956
        count = 1
        val = 5059007
#29 0x00000000004d31a6 in Frecursive_edit () at keyboard.c:1018
        count = 0
        buffer = 10762242
#30 0x00000000004d169a in main (argc=3, argv=0x7f7fffffdb70) at emacs.c:1833
        dummy = 140187730444288
        stack_bottom_variable = 0 '\0'
        do_initial_setlocale = 1
        skip_args = 0
        rlim = {
  rlim_cur = 8720384, 
  rlim_max = 33554432
}
        no_loadup = 0
        junk = 0x0
        dname_arg = 0x0

Lisp Backtrace:
"eval-last-sexp-1" (0xffffca28)
"eval-last-sexp" (0xffffcfa8)
"call-interactively" (0xffffd3b8)

-- 
Kazuhiro Ito