1
0
forked from aniani/vim

patch 9.1.0177: Coverity reports dead code

Problem:  Coverity reports dead code.
Solution: Remove the dead code. Also fix a mistake in ml_get_pos_len()
          and update some comments (zeertzjq).

closes: #14189

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq
2024-03-13 20:42:26 +01:00
committed by Christian Brabandt
parent 253ff4dece
commit 8c55d60658
7 changed files with 29 additions and 23 deletions

View File

@@ -107,7 +107,7 @@ copyFoldingState(win_T *wp_from, win_T *wp_to)
// hasAnyFolding() {{{2
/*
* Return TRUE if there may be folded lines in the current window.
* Return TRUE if there may be folded lines in window "win".
*/
int
hasAnyFolding(win_T *win)
@@ -551,7 +551,7 @@ checkCloseRec(garray_T *gap, linenr_T lnum, int level)
return retval;
}
// foldCreateAllowed() {{{2
// foldManualAllowed() {{{2
/*
* Return TRUE if it's allowed to manually create or delete a fold.
* Give an error message and return FALSE if not.
@@ -1089,7 +1089,7 @@ foldAdjustVisual(void)
mb_adjust_cursor();
}
// cursor_foldstart() {{{2
// foldAdjustCursor() {{{2
/*
* Move the cursor to the first line of a closed fold.
*/

View File

@@ -2686,7 +2686,7 @@ ml_get_len(linenr_T lnum)
colnr_T
ml_get_pos_len(pos_T *pos)
{
return ml_get_buf_len(curbuf, curwin->w_cursor.lnum) - pos->col;
return ml_get_buf_len(curbuf, pos->lnum) - pos->col;
}
// return length (excluding the NUL) of the cursor line
@@ -3582,7 +3582,7 @@ ml_replace(linenr_T lnum, char_u *line, int copy)
* Replace a line for the current buffer. Like ml_replace() with:
* "len_arg" is the length of the text, excluding NUL.
* If "has_props" is TRUE then "line_arg" includes the text properties and
* "len_arg" includes the NUL of the text.
* "len_arg" includes the NUL of the text and text properties.
* When "copy" is TRUE copy the text into allocated memory, otherwise
* "line_arg" must be allocated and will be consumed here.
*/

View File

@@ -849,8 +849,8 @@ op_delete(oparg_T *oap)
}
else
beginline(0); // cursor in column 0
truncate_line(FALSE); // delete the rest of the line
// leave cursor past last char in line
truncate_line(FALSE); // delete the rest of the line,
// leaving cursor past last char in line
if (oap->line_count > 1)
u_clearline(); // "U" command not possible after "2cc"
}
@@ -1494,16 +1494,13 @@ swapchar(int op_type, pos_T *pos)
void
op_insert(oparg_T *oap, long count1)
{
long ins_len, pre_textlen = 0;
char_u *firstline, *ins_text;
long pre_textlen = 0;
colnr_T ind_pre_col = 0, ind_post_col;
int ind_pre_vcol = 0, ind_post_vcol = 0;
struct block_def bd;
int i;
pos_T t1;
pos_T start_insert;
// offset when cursor was moved in insert mode
int offset = 0;
// edit() changes this - record it for OP_APPEND
bd.is_MAX = (curwin->w_curswant == MAXCOL);
@@ -1540,15 +1537,10 @@ op_insert(oparg_T *oap, long count1)
// Get indent information
ind_pre_col = (colnr_T)getwhitecols_curline();
ind_pre_vcol = get_indent();
firstline = ml_get(oap->start.lnum) + bd.textcol;
pre_textlen = ml_get_len(oap->start.lnum) - bd.textcol;
if (oap->op_type == OP_APPEND)
{
firstline += bd.textlen;
pre_textlen -= bd.textlen;
}
}
if (oap->op_type == OP_APPEND)
{
@@ -1601,10 +1593,14 @@ op_insert(oparg_T *oap, long count1)
if (oap->block_mode)
{
long ins_len;
char_u *firstline, *ins_text;
struct block_def bd2;
int did_indent = FALSE;
size_t len;
int add;
// offset when cursor was moved in insert mode
int offset = 0;
// If indent kicked in, the firstline might have changed
// but only do that, if the indent actually increased.
@@ -2654,6 +2650,7 @@ do_addsub(
uvarnumber_T n;
uvarnumber_T oldn;
char_u *ptr;
int linelen;
int c;
int todel;
int do_hex;
@@ -2687,9 +2684,10 @@ do_addsub(
curwin->w_cursor = *pos;
ptr = ml_get(pos->lnum);
linelen = ml_get_len(pos->lnum);
col = pos->col;
if (*ptr == NUL || col + !!save_coladd >= (int)STRLEN(ptr))
if (col + !!save_coladd >= linelen)
goto theend;
/*
@@ -2869,8 +2867,7 @@ do_addsub(
// get the number value (unsigned)
if (visual && VIsual_mode != 'V')
maxlen = (curbuf->b_visual.vi_curswant == MAXCOL
? (int)STRLEN(ptr) - col
: length);
? linelen - col : length);
int overflow = FALSE;
vim_str2nr(ptr + col, &pre, &length,

View File

@@ -6203,7 +6203,7 @@ vgr_match_buflines(
else
{
char_u *str = ml_get_buf(buf, lnum, FALSE);
int line_len = ml_get_buf_len(buf, lnum);
colnr_T linelen = ml_get_buf_len(buf, lnum);
int score;
int_u matches[MAX_FUZZY_MATCHES];
int_u sz = ARRAY_LENGTH(matches);
@@ -6242,7 +6242,7 @@ vgr_match_buflines(
if ((flags & VGR_GLOBAL) == 0)
break;
col = matches[pat_len - 1] + col + 1;
if (col > line_len)
if (col > linelen)
break;
}
}
@@ -6612,7 +6612,7 @@ ex_vimgrep(exarg_T *eap)
goto theend;
}
// Jump to first match if the current window is not 'winfixbuf'
// Jump to first match.
if (!qf_list_empty(qf_get_curlist(qi)))
{
if ((args.flags & VGR_NOJUMP) == 0)

View File

@@ -508,7 +508,6 @@ spell_suggest(int count)
++badlen;
end_visual_mode();
// make sure we don't include the NUL at the end of the line
line = ml_get_curline();
if (badlen > ml_get_curline_len() - (int)curwin->w_cursor.col)
badlen = ml_get_curline_len() - (int)curwin->w_cursor.col;
}

View File

@@ -2364,6 +2364,14 @@ func Test_normal30_changecase()
%d
call assert_beeps('norm! ~')
" Test with multiple lines
call setline(1, ['AA', 'BBBB', 'CCCCCC', 'DDDDDDDD'])
norm! ggguG
call assert_equal(['aa', 'bbbb', 'cccccc', 'dddddddd'], getline(1, '$'))
norm! GgUgg
call assert_equal(['AA', 'BBBB', 'CCCCCC', 'DDDDDDDD'], getline(1, '$'))
%d
" Test for changing case across lines using 'whichwrap'
call setline(1, ['aaaaaa', 'aaaaaa'])
normal! gg10~

View File

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