[vim/vim] null_string as {sub} in substitute() crashes Vim when used in a function (Issue #18309)

2 views
Skip to first unread message

Peter Kenny

unread,
Sep 15, 2025, 5:30:26 PM (3 days ago) Sep 15
to vim/vim, Subscribed
kennypete created an issue (vim/vim#18309)

Using null_string as either {sub} and/or {flags} to substitute() at the script level works fine. The following script demonstrates that in its first three examples. (:1,10so)

Further, {flags} can be null_string when substitute() is within either a def or lambda function. The fourth and fifth examples show that. (:1,23so)

However, if {sub} is null_string in a def or lambda function, gVim freezes for a moment, then crashes. In WSL, it also crashes, though there is a Segmentation fault message. (:so) A screenshot follows the script showing what is generated.

[Windows gVim 9.1.1747 and WSL Vim 9.1.496]

vim9script

# '', '' works
echo 'Vimp'->substitute('p', '', '')

# '', null_string works
echo 'Vimp'->substitute('p', '', null_string)

# null_string, null_string works
echo 'Vimp'->substitute('p', null_string, null_string)

# def function with '', null_string works
def F1(s: string): string
    return s->substitute('p', '', null_string)
enddef
echo 'Vimp'->F1()

# lambda function with '', null_string works
const F2: func = (s: string): string => {
    return s->substitute('p', '', null_string)
  }
echo 'Vimp'->F2()

# def function with null_string, null_string crashes Vim
def C1(s: string): string
    return s->substitute('p', null_string, null_string)
enddef
echo 'Vimp'->C1()

# lambda function with null_string, null_string crashes Vim
const C2: func = (s: string): string => {
    return s->substitute('p', null_string, null_string)
  }
echo 'Vimp'->C2()
segmentation-fault.png (view on web)


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/18309@github.com>

Christian Brabandt

unread,
Sep 16, 2025, 3:25:32 PM (2 days ago) Sep 16
to vim/vim, Subscribed

Closed #18309 as completed via afa2a81.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/18309/issue_event/19734167582@github.com>

Reply all
Reply to author
Forward
0 new messages