Skip to content

Commit 8c55d60

Browse files
zeertzjqchrisbra
authored andcommitted
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>
1 parent 253ff4d commit 8c55d60

7 files changed

Lines changed: 29 additions & 23 deletions

File tree

src/fold.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ copyFoldingState(win_T *wp_from, win_T *wp_to)
107107

108108
// hasAnyFolding() {{{2
109109
/*
110-
* Return TRUE if there may be folded lines in the current window.
110+
* Return TRUE if there may be folded lines in window "win".
111111
*/
112112
int
113113
hasAnyFolding(win_T *win)
@@ -551,7 +551,7 @@ checkCloseRec(garray_T *gap, linenr_T lnum, int level)
551551
return retval;
552552
}
553553

554-
// foldCreateAllowed() {{{2
554+
// foldManualAllowed() {{{2
555555
/*
556556
* Return TRUE if it's allowed to manually create or delete a fold.
557557
* Give an error message and return FALSE if not.
@@ -1089,7 +1089,7 @@ foldAdjustVisual(void)
10891089
mb_adjust_cursor();
10901090
}
10911091

1092-
// cursor_foldstart() {{{2
1092+
// foldAdjustCursor() {{{2
10931093
/*
10941094
* Move the cursor to the first line of a closed fold.
10951095
*/

src/memline.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,7 +2686,7 @@ ml_get_len(linenr_T lnum)
26862686
colnr_T
26872687
ml_get_pos_len(pos_T *pos)
26882688
{
2689-
return ml_get_buf_len(curbuf, curwin->w_cursor.lnum) - pos->col;
2689+
return ml_get_buf_len(curbuf, pos->lnum) - pos->col;
26902690
}
26912691

26922692
// return length (excluding the NUL) of the cursor line
@@ -3582,7 +3582,7 @@ ml_replace(linenr_T lnum, char_u *line, int copy)
35823582
* Replace a line for the current buffer. Like ml_replace() with:
35833583
* "len_arg" is the length of the text, excluding NUL.
35843584
* If "has_props" is TRUE then "line_arg" includes the text properties and
3585-
* "len_arg" includes the NUL of the text.
3585+
* "len_arg" includes the NUL of the text and text properties.
35863586
* When "copy" is TRUE copy the text into allocated memory, otherwise
35873587
* "line_arg" must be allocated and will be consumed here.
35883588
*/

src/ops.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,8 @@ op_delete(oparg_T *oap)
849849
}
850850
else
851851
beginline(0); // cursor in column 0
852-
truncate_line(FALSE); // delete the rest of the line
853-
// leave cursor past last char in line
852+
truncate_line(FALSE); // delete the rest of the line,
853+
// leaving cursor past last char in line
854854
if (oap->line_count > 1)
855855
u_clearline(); // "U" command not possible after "2cc"
856856
}
@@ -1494,16 +1494,13 @@ swapchar(int op_type, pos_T *pos)
14941494
void
14951495
op_insert(oparg_T *oap, long count1)
14961496
{
1497-
long ins_len, pre_textlen = 0;
1498-
char_u *firstline, *ins_text;
1497+
long pre_textlen = 0;
14991498
colnr_T ind_pre_col = 0, ind_post_col;
15001499
int ind_pre_vcol = 0, ind_post_vcol = 0;
15011500
struct block_def bd;
15021501
int i;
15031502
pos_T t1;
15041503
pos_T start_insert;
1505-
// offset when cursor was moved in insert mode
1506-
int offset = 0;
15071504

15081505
// edit() changes this - record it for OP_APPEND
15091506
bd.is_MAX = (curwin->w_curswant == MAXCOL);
@@ -1540,14 +1537,9 @@ op_insert(oparg_T *oap, long count1)
15401537
// Get indent information
15411538
ind_pre_col = (colnr_T)getwhitecols_curline();
15421539
ind_pre_vcol = get_indent();
1543-
firstline = ml_get(oap->start.lnum) + bd.textcol;
15441540
pre_textlen = ml_get_len(oap->start.lnum) - bd.textcol;
1545-
15461541
if (oap->op_type == OP_APPEND)
1547-
{
1548-
firstline += bd.textlen;
15491542
pre_textlen -= bd.textlen;
1550-
}
15511543
}
15521544

15531545
if (oap->op_type == OP_APPEND)
@@ -1601,10 +1593,14 @@ op_insert(oparg_T *oap, long count1)
16011593

16021594
if (oap->block_mode)
16031595
{
1596+
long ins_len;
1597+
char_u *firstline, *ins_text;
16041598
struct block_def bd2;
16051599
int did_indent = FALSE;
16061600
size_t len;
16071601
int add;
1602+
// offset when cursor was moved in insert mode
1603+
int offset = 0;
16081604

16091605
// If indent kicked in, the firstline might have changed
16101606
// but only do that, if the indent actually increased.
@@ -2654,6 +2650,7 @@ do_addsub(
26542650
uvarnumber_T n;
26552651
uvarnumber_T oldn;
26562652
char_u *ptr;
2653+
int linelen;
26572654
int c;
26582655
int todel;
26592656
int do_hex;
@@ -2687,9 +2684,10 @@ do_addsub(
26872684

26882685
curwin->w_cursor = *pos;
26892686
ptr = ml_get(pos->lnum);
2687+
linelen = ml_get_len(pos->lnum);
26902688
col = pos->col;
26912689

2692-
if (*ptr == NUL || col + !!save_coladd >= (int)STRLEN(ptr))
2690+
if (col + !!save_coladd >= linelen)
26932691
goto theend;
26942692

26952693
/*
@@ -2869,8 +2867,7 @@ do_addsub(
28692867
// get the number value (unsigned)
28702868
if (visual && VIsual_mode != 'V')
28712869
maxlen = (curbuf->b_visual.vi_curswant == MAXCOL
2872-
? (int)STRLEN(ptr) - col
2873-
: length);
2870+
? linelen - col : length);
28742871

28752872
int overflow = FALSE;
28762873
vim_str2nr(ptr + col, &pre, &length,

src/quickfix.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6203,7 +6203,7 @@ vgr_match_buflines(
62036203
else
62046204
{
62056205
char_u *str = ml_get_buf(buf, lnum, FALSE);
6206-
int line_len = ml_get_buf_len(buf, lnum);
6206+
colnr_T linelen = ml_get_buf_len(buf, lnum);
62076207
int score;
62086208
int_u matches[MAX_FUZZY_MATCHES];
62096209
int_u sz = ARRAY_LENGTH(matches);
@@ -6242,7 +6242,7 @@ vgr_match_buflines(
62426242
if ((flags & VGR_GLOBAL) == 0)
62436243
break;
62446244
col = matches[pat_len - 1] + col + 1;
6245-
if (col > line_len)
6245+
if (col > linelen)
62466246
break;
62476247
}
62486248
}
@@ -6612,7 +6612,7 @@ ex_vimgrep(exarg_T *eap)
66126612
goto theend;
66136613
}
66146614

6615-
// Jump to first match if the current window is not 'winfixbuf'
6615+
// Jump to first match.
66166616
if (!qf_list_empty(qf_get_curlist(qi)))
66176617
{
66186618
if ((args.flags & VGR_NOJUMP) == 0)

src/spellsuggest.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,6 @@ spell_suggest(int count)
508508
++badlen;
509509
end_visual_mode();
510510
// make sure we don't include the NUL at the end of the line
511-
line = ml_get_curline();
512511
if (badlen > ml_get_curline_len() - (int)curwin->w_cursor.col)
513512
badlen = ml_get_curline_len() - (int)curwin->w_cursor.col;
514513
}

src/testdir/test_normal.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,6 +2364,14 @@ func Test_normal30_changecase()
23642364
%d
23652365
call assert_beeps('norm! ~')
23662366

2367+
" Test with multiple lines
2368+
call setline(1, ['AA', 'BBBB', 'CCCCCC', 'DDDDDDDD'])
2369+
norm! ggguG
2370+
call assert_equal(['aa', 'bbbb', 'cccccc', 'dddddddd'], getline(1, '$'))
2371+
norm! GgUgg
2372+
call assert_equal(['AA', 'BBBB', 'CCCCCC', 'DDDDDDDD'], getline(1, '$'))
2373+
%d
2374+
23672375
" Test for changing case across lines using 'whichwrap'
23682376
call setline(1, ['aaaaaa', 'aaaaaa'])
23692377
normal! gg10~

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
177,
707709
/**/
708710
176,
709711
/**/

0 commit comments

Comments
 (0)