lichray/nvi2

-c option doesn't work properly with USE_WIDECHAR=ON

mohd-akram opened this issue · 3 comments

Tested on FreeBSD 12.1:

$ cd build
$ cmake . && make
$ echo foobar > file
$ ./nvi -e -c '/foo/p' file
-c option, 1: file: read lock was unavailable
file: 1 lines, 6 characters
Press Enter to continue:
$ cmake -DUSE_WIDECHAR=OFF . && make
$ ./nvi -e -c '/foo/p' file
foobar
Press Enter to continue:

Found the bug. When f_search does db_get, ep->c_lp wide string cache is overwritten (search pattern becomes line content) (such a bad idea to cache line that...).
Minimal fix: before ex/ex.c:1915, copy the string ecp->cp, ecp->clen out.
Proper fix: f_search and b_search backup the pattern.

Found the issue. ex_run_str is called with nocopy=1. In wide char mode, this causes the pointer to refer to the internal conv buffer from the call to CHAR2INT with gp->c_option. This is then overwritten later on by db_get in the call to FILE2INT there.

Yes, that's a very minimal fix (common/exf.c:553). Can you propose that?