int old_char = NUL;
char_u *nextcomm;
- // Avoid a UMR warning from Purify, only save the character if it has been
- // written before.
+ // Only save and overwrite the character when it is not the NUL terminator
+ // already. "str" may be a read-only empty string: tv_get_string() falls
+ // back to a "" literal for a NULL string or on a type error, and writing
+ // at "col" would then crash.
+ // This also avoids a UMR warning from Purify.
if (col < len)
+ {
old_char = str[col];
- str[col] = NUL;
+ str[col] = NUL;
+ }
nextcomm = str;
#ifdef FEAT_EVAL
xp->xp_line = str;
xp->xp_col = col;
- str[col] = old_char;
+ if (col < len)
+ str[col] = old_char;
}
/*
call assert_equal('var', getcompletiontype('let v:n'))
call assert_equal('function', getcompletiontype('call tag'))
call assert_equal('help', getcompletiontype('help '))
+ " must not write into a read-only empty string
+ call assert_equal('command', getcompletiontype(test_null_string()))
+ call assert_equal(getcompletion('', 'cmdline'),
+ \ getcompletion(test_null_string(), 'cmdline'))
+ call assert_fails('call getcompletion([], "cmdline")', 'E730:')
endfunc
func Test_multibyte_expression()