0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.4009: reading one byte beyond the end of the line

Problem:    Reading one byte beyond the end of the line.
Solution:   Check for NUL byte first.
This commit is contained in:
Bram Moolenaar
2022-01-05 16:50:40 +00:00
parent 677658ae49
commit d3a117814d
4 changed files with 17 additions and 2 deletions

View File

@@ -3632,7 +3632,8 @@ find_ex_command(
} }
// Check for "++nr" and "--nr". // Check for "++nr" and "--nr".
if (p == eap->cmd && p[0] == p[1] && (*p == '+' || *p == '-')) if (p == eap->cmd && p[0] != NUL && p[0] == p[1]
&& (*p == '+' || *p == '-'))
{ {
eap->cmdidx = *p == '+' ? CMD_increment : CMD_decrement; eap->cmdidx = *p == '+' ? CMD_increment : CMD_decrement;
return eap->cmd + 2; return eap->cmd + 2;

View File

@@ -3537,6 +3537,17 @@ def Test_numbered_function_reference()
unlet g:mydict unlet g:mydict
enddef enddef
def Test_go_beyond_end_of_cmd()
# this was reading the byte after the end of the line
var lines =<< trim END
def F()
cal
enddef
defcompile
END
CheckScriptFailure(lines, 'E476:')
enddef
if has('python3') if has('python3')
def Test_python3_heredoc() def Test_python3_heredoc()
py3 << trim EOF py3 << trim EOF

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
4009,
/**/ /**/
4008, 4008,
/**/ /**/

View File

@@ -2781,7 +2781,8 @@ compile_def_function(
cmd = ea.cmd; cmd = ea.cmd;
if ((*cmd != '$' || starts_with_colon) if ((*cmd != '$' || starts_with_colon)
&& (starts_with_colon || !(*cmd == '\'' && (starts_with_colon || !(*cmd == '\''
|| (cmd[0] == cmd[1] && (*cmd == '+' || *cmd == '-'))))) || (cmd[0] != NUL && cmd[0] == cmd[1]
&& (*cmd == '+' || *cmd == '-')))))
{ {
ea.cmd = skip_range(ea.cmd, TRUE, NULL); ea.cmd = skip_range(ea.cmd, TRUE, NULL);
if (ea.cmd > cmd) if (ea.cmd > cmd)