Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: TRAPINT doesn't work reliably



On Thursday, September 26, 2019 5:25 PM, Peter Stephenson <p.stephenson@xxxxxxxxxxx> wrote:

> It suggests it's going to be quite hard to reproduce elsewhere, though
> I'd still be interesting in the logic where you're defining TRAPINT since
> clearly that's the memory that's getting mishandled.

I don't fully understand what you mean with "the logic where you're
defining TRAPINT," but I have the following code in my `.zshrc`:

    function TRAPINT {
        VIMODE="$VIINS"
        print $1  # for debug only
        return $(( 128 + $1 ))
    }

(I use zsh with vi keybindings and VIMODE indicates on my prompt which
mode I'm in. When I interrupt, start again in insert mode and I want that
to be properly indicated.)


> It's also still suggesting trying to get valgrind to give a bit more
> detail is the best way forward.

Ah, of course. I forgot about valgrind since I could only reproduce this
bug if I checked out the tag `zsh-5.7.1`.

I did manage to capture the bug with valgrind on `master` using the
following sequence of commands (output tidied):

$ git checkout master
$ git checkout zsh-5.7.1 -- Config/version.mk
$ ./configure --enable-zsh-debug && make && sudo make install
$ valgrind --leak-check=full --log-file=zsh-valgrind.log /usr/local/bin/zsh
/usr/share/zsh-antigen/antigen.zsh:2134: parse error near `\n'
$ ll
TRAPINT:1: not an identifier:

Here, `ll [TAB]` was executed in the new shell. I don't get the error
message "/usr/share/zsh-antigen/antigen.zsh:2134: parse error near `\n'"
when I start zsh without valgrind, so I guess that can be ignored.


What valgrind captured:

Invalid read of size 1
   at 0x4838CC2: __strlen_sse2 (vg_replace_strmem.c:462)
   by 0x1B0792: dupstring (string.c:39)
   by 0x19BC70: ecgetstr (parse.c:2809)
   by 0x144095: addvars (exec.c:2429)
   by 0x1404DB: execsimple (exec.c:1237)
   by 0x140A85: execlist (exec.c:1378)
   by 0x14038F: execode (exec.c:1194)
   by 0x14DCB0: runshfunc (exec.c:5980)
   by 0x14D2E8: doshfunc (exec.c:5830)
   by 0x1AF4D1: dotrapargs (signals.c:1371)
   by 0x1AFA8F: dotrap (signals.c:1487)
   by 0x1AF18C: handletrap (signals.c:1202)
 Address 0x566b948 is 0 bytes after a block of size 328 free'd
   at 0x48369AB: free (vg_replace_malloc.c:530)
   by 0x13D8F3: zcontext_restore_partial (context.c:108)
   by 0x13DA56: zcontext_restore (context.c:119)
   by 0x175A04: parse_subscript (lex.c:1697)
   by 0x18B7F1: getindex (params.c:1858)
   by 0x18C132: fetchvalue (params.c:2106)
   by 0x1B6304: paramsubst (subst.c:2516)
   by 0x1B1DB9: stringsubst (subst.c:322)
   by 0x1B1108: prefork (subst.c:142)
   by 0x14486C: execsubst (exec.c:2570)
   by 0x1772E9: execfor (loop.c:98)
   by 0x148469: execcmd_exec (exec.c:3913)
 Block was alloc'd at
   at 0x483577F: malloc (vg_replace_malloc.c:299)
   by 0x13D5D6: zcontext_save_partial (context.c:58)
   by 0x13D7E9: zcontext_save (context.c:82)
   by 0x1758A7: parse_subscript (lex.c:1661)
   by 0x18B7F1: getindex (params.c:1858)
   by 0x18C132: fetchvalue (params.c:2106)
   by 0x1B6304: paramsubst (subst.c:2516)
   by 0x1B1DB9: stringsubst (subst.c:322)
   by 0x1B1108: prefork (subst.c:142)
   by 0x14486C: execsubst (exec.c:2570)
   by 0x1772E9: execfor (loop.c:98)
   by 0x148469: execcmd_exec (exec.c:3913)


I hope this helps. Thank you for your time and developing zsh!

Cheers,
Dennis



Messages sorted by: Reverse Date, Date, Thread, Author