New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

termguicolors有効時にt_Coの値がおかしいと落ちる #1157

Closed
kuuote opened this Issue Mar 12, 2018 · 7 comments

Comments

Projects
None yet
3 participants
@kuuote

kuuote commented Mar 12, 2018

報告

termguicolorsを有効にした状態でt_Coに無効な値を入れるとSegmentation faultを起こします

Vimのバージョン

8.0.1599

OSの種類/ディストリ/バージョン

Linux Porteus V3.2.2 64bit

再現手順

vim -u NONE -Nで起動した後に

:set termguicolors
:set t_Co=

を実行する

その他

gdbで走らせるとこのように出ます

0x000000000062672b in out_str (s=0x7 <error: Cannot access memory at address 0x7>) at term.c:2705
2705        if (s != NULL && *s)

btの結果です

#0  0x000000000062672b in out_str (s=0x7 <error: Cannot access memory at address 0x7>) at term.c:2705
#1  0x00000000005c9dea in screen_start_highlight (attr=0) at screen.c:8133
#2  0x00000000005c46f3 in screen_char (off=0, row=0, col=0) at screen.c:8346
#3  0x00000000005b6b23 in screen_line (row=0, coloff=0, endcol=4, clear_width=154, rlflag=0) at screen.c:6311
#4  0x00000000005c1f8c in win_line (wp=0x98e560, lnum=1, startrow=0, endrow=71, nochange=1) at screen.c:5531
#5  0x00000000005ba690 in win_update (wp=0x98e560) at screen.c:2119
#6  0x00000000005b6194 in update_screen (type_arg=0) at screen.c:753
#7  0x00000000006a6d24 in main_loop (cmdwin=0, noexmode=0) at main.c:1236
#8  0x00000000006a58fb in vim_main2 () at main.c:915
#9  0x00000000006a2db5 in main (argc=1, argv=0x7fffffffd9b8) at main.c:443
@mattn

This comment has been minimized.

Member

mattn commented Mar 12, 2018

もしよければ :version の内容を貼って貰っても良いでしょうか。以下のバージョン(少し古い)では再現しませんでした。

:ver
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Feb 13 2018 00:19:23)
Included patches: 1-1505
Compiled by mattn@instance-1
Huge version without GUI.  Features included (+) or not (-):
+acl               -clientserver      +dialog_con        +find_in_path      +keymap            +modify_fname      +multi_byte        +profile           +statusline        +textobjects       +wildignore
+arabic            -clipboard         +diff              +float             +lambda            +mouse             +multi_lang        -python            -sun_workshop      +timers            +wildmenu
+autocmd           +cmdline_compl     +digraphs          +folding           +langmap           -mouseshape        -mzscheme          -python3           +syntax            +title             +windows
-autoservername    +cmdline_hist      -dnd               -footer            +libcall           +mouse_dec         +netbeans_intg     +quickfix          +tag_binary        -toolbar           +writebackup
-balloon_eval      +cmdline_info      -ebcdic            +fork()            +linebreak         -mouse_gpm         +num64             +reltime           +tag_old_static    +user_commands     -X11
+balloon_eval_term +comments          +emacs_tags        -gettext           +lispindent        -mouse_jsbterm     +packages          +rightleft         -tag_any_white     +vertsplit         -xfontset
-browse            +conceal           +eval              -hangul_input      +listcmds          +mouse_netterm     +path_extra        -ruby              -tcl               +virtualedit       -xim
++builtin_terms    +cryptv            +ex_extra          +iconv             +localmap          +mouse_sgr         -perl              +scrollbind        +termguicolors     +visual            -xpm
+byte_offset       +cscope            +extra_search      +insert_expand     -lua               -mouse_sysmouse    +persistent_undo   +signs             +terminal          +visualextra       -xsmp
+channel           +cursorbind        +farsi             +job               +menu              +mouse_urxvt       +postscript        +smartindent       +terminfo          +viminfo           -xterm_clipboard
+cindent           +cursorshape       +file_in_path      +jumplist          +mksession         +mouse_xterm       +printer           +startuptime       +termresponse      +vreplace          -xterm_save
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L/usr/local/lib -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -ldl
@mattn

This comment has been minimized.

Member

mattn commented Mar 12, 2018

diff --git a/src/option.c b/src/option.c
index 084e5e1..9ecb2cd 100644
--- a/src/option.c
+++ b/src/option.c
@@ -6764,7 +6764,7 @@ did_set_string_option(
                t_colors = colors;
                if (t_colors <= 1)
                {
-                   if (new_value_alloced)
+                   if (new_value_alloced && T_CCO != empty_option)
                        vim_free(T_CCO);
                    T_CCO = empty_option;
                }

なんか最近入ったバグな気がする。

追記 これでもダメっぽい

@ichizok

This comment has been minimized.

Member

ichizok commented Mar 12, 2018

8.0.1544 が原因のよう
vim/vim@d4fc577

@mattn mattn added the kind/bug label Mar 12, 2018

@kuuote

This comment has been minimized.

kuuote commented Mar 12, 2018

遅くなってすみません、githubのHEADからビルドしたのでバージョンは現時点での最新になります

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Mar 12 2018 12:00:45)
Included patches: 1-1599
Compiled by guest@porteus
Huge version with GTK2 GUI.  Features included (+) or not (-):
+acl               +comments          +file_in_path      +linebreak         +mouse_urxvt       +quickfix          +terminal          +windows
+arabic            +conceal           +find_in_path      +lispindent        +mouse_xterm       +reltime           +terminfo          +writebackup
+autocmd           +cryptv            +float             +listcmds          +multi_byte        +rightleft         +termresponse      +X11
-autoservername    +cscope            +folding           +localmap          +multi_lang        -ruby              +textobjects       -xfontset
+balloon_eval      +cursorbind        -footer            -lua               -mzscheme          +scrollbind        +timers            +xim
+balloon_eval_term +cursorshape       +fork()            +menu              +netbeans_intg     +signs             +title             +xpm
+browse            +dialog_con_gui    +gettext           +mksession         +num64             +smartindent       +toolbar           +xsmp_interact
++builtin_terms    +diff              -hangul_input      +modify_fname      +packages          +startuptime       +user_commands     +xterm_clipboard
+byte_offset       +digraphs          +iconv             +mouse             +path_extra        +statusline        +vertsplit         -xterm_save
+channel           +dnd               +insert_expand     +mouseshape        -perl              -sun_workshop      +virtualedit
+cindent           -ebcdic            +job               +mouse_dec         +persistent_undo   +syntax            +visual
+clientserver      +emacs_tags        +jumplist          +mouse_gpm         +postscript        +tag_binary        +visualextra
+clipboard         +eval              +keymap            -mouse_jsbterm     +printer           +tag_old_static    +viminfo
+cmdline_compl     +ex_extra          +lambda            +mouse_netterm     +profile           -tag_any_white     +vreplace
+cmdline_hist      +extra_search      +langmap           +mouse_sgr         -python            -tcl               +wildignore
+cmdline_info      +farsi             +libcall           -mouse_sysmouse    -python3           +termguicolors     +wildmenu
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-2.0 -I/usr/lib64/gtk-2.0/include -I/usr/include/pango-1.0 -I
/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/libdrm -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/inclu
de/pango-1.0 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib
-2.0 -I/usr/lib64/glib-2.0/include   -g -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang   -L/usr/local/lib -Wl,--as-needed -o vim   -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpan
goft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -lncurses -lelf -lnsl  -lacl -l
attr -lgpm -ldl

screen.cのscreen_start_highlightの中でattrentry_Tというものを取得していて、これがカラーターミナル(以下cterm)と白黒ターミナル(以下term)の二種類あって、これを判定するのにIS_CTERMというマクロが使われてるんですが(vim.h内にあります)
これがtermguicolors時には常に真を返すようになっているため、cterm用のattrentry_Tが取得されるが、今回落ちる場所ではIS_CTERMを使わずに実行されるかが決まって、その中ではterm用の構造体が期待されているのにcterm用の構造体が渡ってきているためエラーになっているようです。

diff --git a/src/screen.c b/src/screen.c
index 5ab2e85fc..77a3c1895 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -8127,7 +8127,7 @@ screen_start_highlight(int attr)
                        term_bg_color(aep->ae_u.cterm.bg_color - 1);
                }
 
-               if (t_colors <= 1)
+               if (!IS_CTERM)
                {
                    if (aep->ae_u.term.start != NULL)
                        out_str(aep->ae_u.term.start);

パッチとして正しいのかは分かりませんがこれで直るはずです。

@mattn

This comment has been minimized.

Member

mattn commented Mar 12, 2018

パッチ送ってみませんか。最近だと pull-request からでも取り込んで貰えます。

@kuuote

This comment has been minimized.

kuuote commented Mar 12, 2018

vim/vim#2710
周りのプルリクとGoogle翻訳の力を借りながら書いたのでひどい英語だとは思いますが送ってみました。
色々調べていただきありがとうございました。

@mattn

This comment has been minimized.

Member

mattn commented Mar 13, 2018

Patch 8.0.1600

お疲れ様でした。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment