aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2014-08-08 09:27:09 -0400
committerJustin M. Keyes <justinkz@gmail.com>2014-08-08 09:27:09 -0400
commit19f44fda8bc74abdcd13deca47be99b151f69239 (patch)
treef79a83af7a9b44f89b26cc3fe7a37a87ca20d28b /src
parent54d49931255090ebf33c342aed6fbe9f9ca308e6 (diff)
parentbdd82b0da729b77381219927eb174b8e4d2054f8 (diff)
downloadrneovim-19f44fda8bc74abdcd13deca47be99b151f69239.tar.gz
rneovim-19f44fda8bc74abdcd13deca47be99b151f69239.tar.bz2
rneovim-19f44fda8bc74abdcd13deca47be99b151f69239.zip
Merge pull request #985 from fwalch/clang-analyzer-dead-assignments
Clang analyzer: fix dead stores / reduce scope
Diffstat (limited to 'src')
-rw-r--r--src/nvim/arabic.c13
-rw-r--r--src/nvim/garray.c2
-rw-r--r--src/nvim/screen.c57
-rw-r--r--src/nvim/search.c37
-rw-r--r--src/nvim/spell.c50
-rw-r--r--src/nvim/syntax.c17
-rw-r--r--src/nvim/window.c2
7 files changed, 72 insertions, 106 deletions
diff --git a/src/nvim/arabic.c b/src/nvim/arabic.c
index e39ee8012b..7880c66e1e 100644
--- a/src/nvim/arabic.c
+++ b/src/nvim/arabic.c
@@ -1361,24 +1361,19 @@ static int half_shape(int c)
int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1,
int next_c)
{
- int curr_c;
- int shape_c;
- int curr_laa;
- int prev_laa;
-
/* Deal only with Arabic character, pass back all others */
if (!A_is_ok(c)) {
return c;
}
/* half-shape current and previous character */
- shape_c = half_shape(prev_c);
+ int shape_c = half_shape(prev_c);
/* Save away current character */
- curr_c = c;
+ int curr_c = c;
- curr_laa = A_firstc_laa(c, *c1p);
- prev_laa = A_firstc_laa(prev_c, prev_c1);
+ int curr_laa = A_firstc_laa(c, *c1p);
+ int prev_laa = A_firstc_laa(prev_c, prev_c1);
if (curr_laa) {
if (A_is_valid(prev_c) && !A_is_f(shape_c) && !A_is_s(shape_c) &&
diff --git a/src/nvim/garray.c b/src/nvim/garray.c
index 033ea9baac..fb76d11f3f 100644
--- a/src/nvim/garray.c
+++ b/src/nvim/garray.c
@@ -159,7 +159,7 @@ char_u *ga_concat_strings_sep(const garray_T *gap, const char *sep)
s = xstpcpy(s, strings[i]);
s = xstpcpy(s, sep);
}
- s = xstpcpy(s, strings[nelem - 1]);
+ strcpy(s, strings[nelem - 1]);
return (char_u *) ret;
}
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 0d0d068b36..1fd872d61c 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -7726,22 +7726,6 @@ void showruler(int always)
static void win_redr_ruler(win_T *wp, int always)
{
-#define RULER_BUF_LEN 70
- char_u buffer[RULER_BUF_LEN];
- int row;
- int fillchar;
- int attr;
- int empty_line = FALSE;
- colnr_T virtcol;
- int i;
- size_t len;
- int o;
- int this_ru_col;
- int off = 0;
- int width = Columns;
-# define WITH_OFF(x) x
-# define WITH_WIDTH(x) x
-
/* If 'ruler' off or redrawing disabled, don't do anything */
if (!p_ru)
return;
@@ -7777,6 +7761,7 @@ static void win_redr_ruler(win_T *wp, int always)
/*
* Check if not in Insert mode and the line is empty (will show "0-1").
*/
+ int empty_line = FALSE;
if (!(State & INSERT)
&& *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL)
empty_line = TRUE;
@@ -7796,6 +7781,13 @@ static void win_redr_ruler(win_T *wp, int always)
|| wp->w_topfill != wp->w_ru_topfill
|| empty_line != wp->w_ru_empty) {
cursor_off();
+
+ int width;
+ int row;
+ int fillchar;
+ int attr;
+ int off;
+
if (wp->w_status_height) {
row = wp->w_winrow + wp->w_height;
fillchar = fillchar_status(&attr, wp == curwin);
@@ -7810,13 +7802,16 @@ static void win_redr_ruler(win_T *wp, int always)
}
/* In list mode virtcol needs to be recomputed */
- virtcol = wp->w_virtcol;
+ colnr_T virtcol = wp->w_virtcol;
if (wp->w_p_list && lcs_tab1 == NUL) {
wp->w_p_list = FALSE;
getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL);
wp->w_p_list = TRUE;
}
+#define RULER_BUF_LEN 70
+ char_u buffer[RULER_BUF_LEN];
+
/*
* Some sprintfs return the length, some return a pointer.
* To avoid portability problems we use strlen() here.
@@ -7824,7 +7819,7 @@ static void win_redr_ruler(win_T *wp, int always)
vim_snprintf((char *)buffer, RULER_BUF_LEN, "%" PRId64 ",",
(wp->w_buffer->b_ml.ml_flags & ML_EMPTY) ? (int64_t)0L
: (int64_t)wp->w_cursor.lnum);
- len = STRLEN(buffer);
+ size_t len = STRLEN(buffer);
col_print(buffer + len, RULER_BUF_LEN - len,
empty_line ? 0 : (int)wp->w_cursor.col + 1,
(int)virtcol + 1);
@@ -7834,20 +7829,20 @@ static void win_redr_ruler(win_T *wp, int always)
* On the last line, don't print in the last column (scrolls the
* screen up on some terminals).
*/
- i = (int)STRLEN(buffer);
+ int i = (int)STRLEN(buffer);
get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1);
- o = i + vim_strsize(buffer + i + 1);
+ int o = i + vim_strsize(buffer + i + 1);
if (wp->w_status_height == 0) /* can't use last char of screen */
++o;
- this_ru_col = ru_col - (Columns - width);
+ int this_ru_col = ru_col - (Columns - width);
if (this_ru_col < 0)
this_ru_col = 0;
/* Never use more than half the window/screen width, leave the other
* half for the filename. */
- if (this_ru_col < (WITH_WIDTH(width) + 1) / 2)
- this_ru_col = (WITH_WIDTH(width) + 1) / 2;
- if (this_ru_col + o < WITH_WIDTH(width)) {
- while (this_ru_col + o < WITH_WIDTH(width)) {
+ if (this_ru_col < (width + 1) / 2)
+ this_ru_col = (width + 1) / 2;
+ if (this_ru_col + o < width) {
+ while (this_ru_col + o < width) {
if (has_mbyte)
i += (*mb_char2bytes)(fillchar, buffer + i);
else
@@ -7861,19 +7856,19 @@ static void win_redr_ruler(win_T *wp, int always)
o = 0;
for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) {
o += (*mb_ptr2cells)(buffer + i);
- if (this_ru_col + o > WITH_WIDTH(width)) {
+ if (this_ru_col + o > width) {
buffer[i] = NUL;
break;
}
}
- } else if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width))
- buffer[WITH_WIDTH(width) - this_ru_col] = NUL;
+ } else if (this_ru_col + (int)STRLEN(buffer) > width)
+ buffer[width - this_ru_col] = NUL;
- screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr);
+ screen_puts(buffer, row, this_ru_col + off, attr);
i = redraw_cmdline;
screen_fill(row, row + 1,
- this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer),
- (int)(WITH_OFF(off) + WITH_WIDTH(width)),
+ this_ru_col + off + (int)STRLEN(buffer),
+ (int)(off + width),
fillchar, fillchar, attr);
/* don't redraw the cmdline because of showing the ruler */
redraw_cmdline = i;
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 5c92ef71a9..c995300d56 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -3762,16 +3762,8 @@ current_search (
int forward /* move forward or backwards */
)
{
- pos_T start_pos; /* position before the pattern */
- pos_T orig_pos; /* position of the cursor at beginning */
- pos_T pos; /* position after the pattern */
- int i;
- int dir;
- int result; /* result of various function calls */
bool old_p_ws = p_ws;
- int flags = 0;
pos_T save_VIsual = VIsual;
- int one_char;
/* wrapping should not occur */
p_ws = false;
@@ -3780,11 +3772,11 @@ current_search (
if (VIsual_active && *p_sel == 'e' && lt(VIsual, curwin->w_cursor))
dec_cursor();
- if (VIsual_active) {
- orig_pos = curwin->w_cursor;
+ pos_T orig_pos; /* position of the cursor at beginning */
+ pos_T pos; /* position after the pattern */
- pos = curwin->w_cursor;
- start_pos = VIsual;
+ if (VIsual_active) {
+ orig_pos = pos = curwin->w_cursor;
/* make sure, searching further will extend the match */
if (VIsual_active) {
@@ -3794,10 +3786,10 @@ current_search (
decl(&pos);
}
} else
- orig_pos = pos = start_pos = curwin->w_cursor;
+ orig_pos = pos = curwin->w_cursor;
/* Is the pattern is zero-width? */
- one_char = is_one_char(spats[last_idx].pat);
+ int one_char = is_one_char(spats[last_idx].pat);
if (one_char == -1) {
p_ws = old_p_ws;
return FAIL; /* pattern not found */
@@ -3808,17 +3800,14 @@ current_search (
* so that a match at the current cursor position will be correctly
* captured.
*/
- for (i = 0; i < 2; i++) {
- if (forward)
- dir = i;
- else
- dir = !i;
+ for (int i = 0; i < 2; i++) {
+ int dir = forward ? i : !i;
+ int flags = 0;
- flags = 0;
if (!dir && !one_char)
flags = SEARCH_END;
- result = searchit(curwin, curbuf, &pos, (dir ? FORWARD : BACKWARD),
+ int result = searchit(curwin, curbuf, &pos, (dir ? FORWARD : BACKWARD),
spats[last_idx].pat, (long) (i ? count : 1),
SEARCH_KEEP | flags, RE_SEARCH, 0, NULL);
@@ -3845,13 +3834,13 @@ current_search (
p_ws = old_p_ws;
}
- start_pos = pos;
- flags = forward ? SEARCH_END : 0;
+ int flags = forward ? SEARCH_END : 0;
+ pos_T start_pos = pos;
/* move to match, except for zero-width matches, in which case, we are
* already on the next match */
if (!one_char)
- result = searchit(curwin, curbuf, &pos, (forward ? FORWARD : BACKWARD),
+ searchit(curwin, curbuf, &pos, (forward ? FORWARD : BACKWARD),
spats[last_idx].pat, 0L, flags | SEARCH_KEEP, RE_SEARCH, 0, NULL);
if (!VIsual_active)
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index 875f34f55c..17093571c0 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -1261,28 +1261,12 @@ spell_check (
// For a match mip->mi_result is updated.
static void find_word(matchinf_T *mip, int mode)
{
- idx_T arridx = 0;
- int endlen[MAXWLEN]; // length at possible word endings
- idx_T endidx[MAXWLEN]; // possible word endings
- int endidxcnt = 0;
- int len;
int wlen = 0;
int flen;
- int c;
char_u *ptr;
- idx_T lo;
- idx_T hi;
- idx_T m;
- char_u *s;
- char_u *p;
- int res = SP_BAD;
slang_T *slang = mip->mi_lp->lp_slang;
- unsigned flags;
char_u *byts;
idx_T *idxs;
- bool word_ends;
- bool prefix_found;
- int nobreak_result;
if (mode == FIND_KEEPWORD || mode == FIND_KEEPCOMPOUND) {
// Check for word with matching case in keep-case tree.
@@ -1316,6 +1300,13 @@ static void find_word(matchinf_T *mip, int mode)
if (byts == NULL)
return; // array is empty
+ idx_T arridx = 0;
+ int endlen[MAXWLEN]; // length at possible word endings
+ idx_T endidx[MAXWLEN]; // possible word endings
+ int endidxcnt = 0;
+ int len;
+ int c;
+
// Repeat advancing in the tree until:
// - there is a byte that doesn't match,
// - we reach the end of the tree,
@@ -1356,10 +1347,10 @@ static void find_word(matchinf_T *mip, int mode)
c = ptr[wlen];
if (c == TAB) // <Tab> is handled like <Space>
c = ' ';
- lo = arridx;
- hi = arridx + len - 1;
+ idx_T lo = arridx;
+ idx_T hi = arridx + len - 1;
while (lo < hi) {
- m = (lo + hi) / 2;
+ idx_T m = (lo + hi) / 2;
if (byts[m] > c)
hi = m - 1;
else if (byts[m] < c)
@@ -1393,6 +1384,9 @@ static void find_word(matchinf_T *mip, int mode)
}
}
+ char_u *p;
+ bool word_ends;
+
// Verify that one of the possible endings is valid. Try the longest
// first.
while (endidxcnt > 0) {
@@ -1410,7 +1404,7 @@ static void find_word(matchinf_T *mip, int mode)
word_ends = true;
// The prefix flag is before compound flags. Once a valid prefix flag
// has been found we try compound flags.
- prefix_found = false;
+ bool prefix_found = false;
if (mode != FIND_KEEPWORD && has_mbyte) {
// Compute byte length in original word, length may change
@@ -1418,7 +1412,7 @@ static void find_word(matchinf_T *mip, int mode)
// case-folded word is equal to the keep-case word.
p = mip->mi_word;
if (STRNCMP(ptr, p, wlen) != 0) {
- for (s = ptr; s < ptr + wlen; mb_ptr_adv(s))
+ for (char_u *s = ptr; s < ptr + wlen; mb_ptr_adv(s))
mb_ptr_adv(p);
wlen = (int)(p - mip->mi_word);
}
@@ -1428,10 +1422,9 @@ static void find_word(matchinf_T *mip, int mode)
// prefix ID.
// Repeat this if there are more flags/region alternatives until there
// is a match.
- res = SP_BAD;
for (len = byts[arridx - 1]; len > 0 && byts[arridx] == 0;
--len, ++arridx) {
- flags = idxs[arridx];
+ uint32_t flags = idxs[arridx];
// For the fold-case tree check that the case of the checked word
// matches with what the word in the tree requires.
@@ -1527,7 +1520,7 @@ static void find_word(matchinf_T *mip, int mode)
mip->mi_compoff) != 0) {
// case folding may have changed the length
p = mip->mi_word;
- for (s = ptr; s < ptr + mip->mi_compoff; mb_ptr_adv(s))
+ for (char_u *s = ptr; s < ptr + mip->mi_compoff; mb_ptr_adv(s))
mb_ptr_adv(p);
} else
p = mip->mi_word + mip->mi_compoff;
@@ -1577,7 +1570,7 @@ static void find_word(matchinf_T *mip, int mode)
else if (flags & WF_NEEDCOMP)
continue;
- nobreak_result = SP_OK;
+ int nobreak_result = SP_OK;
if (!word_ends) {
int save_result = mip->mi_result;
@@ -1601,7 +1594,7 @@ static void find_word(matchinf_T *mip, int mode)
// the case-folded word is equal to the keep-case word.
p = mip->mi_fword;
if (STRNCMP(ptr, p, wlen) != 0) {
- for (s = ptr; s < ptr + wlen; mb_ptr_adv(s))
+ for (char_u *s = ptr; s < ptr + wlen; mb_ptr_adv(s))
mb_ptr_adv(p);
mip->mi_compoff = (int)(p - mip->mi_fword);
}
@@ -1661,6 +1654,7 @@ static void find_word(matchinf_T *mip, int mode)
}
}
+ int res = SP_BAD;
if (flags & WF_BANNED)
res = SP_BANNED;
else if (flags & WF_REGION) {
@@ -3767,7 +3761,6 @@ char_u *did_set_spelllang(win_T *wp)
&& !ASCII_ISALPHA(p[3])) {
STRLCPY(region_cp, p + 1, 3);
memmove(p, p + 3, len - (p - lang) - 2);
- len -= 3;
region = region_cp;
} else
dont_use_region = true;
@@ -3780,8 +3773,7 @@ char_u *did_set_spelllang(win_T *wp)
filename = false;
if (len > 3 && lang[len - 3] == '_') {
region = lang + len - 2;
- len -= 3;
- lang[len] = NUL;
+ lang[len - 3] = NUL;
} else
dont_use_region = true;
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index 7dd3453d16..5b9deb184a 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -5684,22 +5684,19 @@ static int syn_compare_syntime(const void *v1, const void *v2)
*/
static void syntime_report(void)
{
- synpat_T *spp;
- proftime_T tm;
- int len;
- int total_count = 0;
- garray_T ga;
- time_entry_T *p;
-
if (!syntax_present(curwin)) {
MSG(_(msg_no_items));
return;
}
+ garray_T ga;
ga_init(&ga, sizeof(time_entry_T), 50);
+
proftime_T total_total = profile_zero();
+ int total_count = 0;
+ time_entry_T *p;
for (int idx = 0; idx < curwin->w_s->b_syn_patterns.ga_len; ++idx) {
- spp = &(SYN_ITEMS(curwin->w_s)[idx]);
+ synpat_T *spp = &(SYN_ITEMS(curwin->w_s)[idx]);
if (spp->sp_time.count > 0) {
p = GA_APPEND_VIA_PTR(time_entry_T, &ga);
p->total = spp->sp_time.total;
@@ -5708,7 +5705,7 @@ static void syntime_report(void)
p->match = spp->sp_time.match;
total_count += spp->sp_time.count;
p->slowest = spp->sp_time.slowest;
- tm = profile_divide(spp->sp_time.total, spp->sp_time.count);
+ proftime_T tm = profile_divide(spp->sp_time.total, spp->sp_time.count);
p->average = tm;
p->id = spp->sp_syn.id;
p->pattern = spp->sp_pattern;
@@ -5723,7 +5720,6 @@ static void syntime_report(void)
" TOTAL COUNT MATCH SLOWEST AVERAGE NAME PATTERN"));
MSG_PUTS("\n");
for (int idx = 0; idx < ga.ga_len && !got_int; ++idx) {
- spp = &(SYN_ITEMS(curwin->w_s)[idx]);
p = ((time_entry_T *)ga.ga_data) + idx;
MSG_PUTS(profile_msg(p->total));
@@ -5745,6 +5741,7 @@ static void syntime_report(void)
MSG_PUTS(" ");
msg_advance(69);
+ int len;
if (Columns < 80)
len = 20; /* will wrap anyway */
else
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 98daa7eca2..52401a12ee 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -1445,7 +1445,6 @@ win_equal_rec (
}
for (fr = topfr->fr_child; fr != NULL; fr = fr->fr_next) {
- n = m = 0;
wincount = 1;
if (fr->fr_next == NULL)
/* last frame gets all that remains (avoid roundoff error) */
@@ -1566,7 +1565,6 @@ win_equal_rec (
}
for (fr = topfr->fr_child; fr != NULL; fr = fr->fr_next) {
- n = m = 0;
wincount = 1;
if (fr->fr_next == NULL)
/* last frame gets all that remains (avoid roundoff error) */