build: enable -Wshadow

Note about shada.c:
- shada_read_next_item_start was intentionally shadowing `unpacked` and
  `i` because many of the macros (e.g. ADDITIONAL_KEY) implicitly
  depended on those variable names.
- Macros were changed to parameterize `unpacked` (but not `i`). Macros
  like CLEAR_GA_AND_ERROR_OUT do control-flow (goto), so any other
  approach is messy.
This commit is contained in:
Justin M. Keyes 2016-03-09 09:52:07 -05:00
parent 5fba815921
commit a70fde1b45
18 changed files with 178 additions and 166 deletions

View File

@ -174,7 +174,7 @@ endif()
# Enable -Wconversion.
if(NOT MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow -Wconversion")
endif()
# gcc 4.0+ sets _FORTIFY_SOURCE=2 automatically. This currently

View File

@ -2380,7 +2380,7 @@ static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv,
int ll_n1 = lp->ll_n1;
// Check whether any of the list items is locked
for (listitem_T *ri = tv_list_first(rettv->vval.v_list);
for (ri = tv_list_first(rettv->vval.v_list);
ri != NULL && ll_li != NULL; ) {
if (tv_check_lock(TV_LIST_ITEM_TV(ll_li)->v_lock,
(const char *)lp->ll_name,
@ -2476,9 +2476,9 @@ notify:
assert(lp->ll_newkey != NULL);
tv_dict_watcher_notify(dict, (char *)lp->ll_newkey, lp->ll_tv, NULL);
} else {
dictitem_T *di = lp->ll_di;
assert(di->di_key != NULL);
tv_dict_watcher_notify(dict, (char *)di->di_key, lp->ll_tv, &oldtv);
dictitem_T *di_ = lp->ll_di;
assert(di_->di_key != NULL);
tv_dict_watcher_notify(dict, (char *)di_->di_key, lp->ll_tv, &oldtv);
tv_clear(&oldtv);
}
}
@ -5234,8 +5234,6 @@ bool garbage_collect(bool testing)
/// @return true, if something was freed.
static int free_unref_items(int copyID)
{
dict_T *dd, *dd_next;
list_T *ll, *ll_next;
bool did_free = false;
// Let all "free" functions know that we are here. This means no
@ -5273,14 +5271,16 @@ static int free_unref_items(int copyID)
}
// PASS 2: free the items themselves.
for (dd = gc_first_dict; dd != NULL; dd = dd_next) {
dict_T *dd_next;
for (dict_T *dd = gc_first_dict; dd != NULL; dd = dd_next) {
dd_next = dd->dv_used_next;
if ((dd->dv_copyID & COPYID_MASK) != (copyID & COPYID_MASK)) {
tv_dict_free_dict(dd);
}
}
for (ll = gc_first_list; ll != NULL; ll = ll_next) {
list_T *ll_next;
for (list_T *ll = gc_first_list; ll != NULL; ll = ll_next) {
ll_next = ll->lv_used_next;
if ((ll->lv_copyID & COPYID_MASK) != (copyID & COPYID_MASK)
&& !tv_list_has_watchers(ll)) {
@ -11508,23 +11508,23 @@ static void dict_list(typval_T *const tv, typval_T *const rettv,
tv_list_alloc_ret(rettv, tv_dict_len(tv->vval.v_dict));
TV_DICT_ITER(tv->vval.v_dict, di, {
typval_T tv = { .v_lock = VAR_UNLOCKED };
typval_T tv_item = { .v_lock = VAR_UNLOCKED };
switch (what) {
case kDictListKeys: {
tv.v_type = VAR_STRING;
tv.vval.v_string = vim_strsave(di->di_key);
tv_item.v_type = VAR_STRING;
tv_item.vval.v_string = vim_strsave(di->di_key);
break;
}
case kDictListValues: {
tv_copy(&di->di_tv, &tv);
tv_copy(&di->di_tv, &tv_item);
break;
}
case kDictListItems: {
// items()
list_T *const sub_l = tv_list_alloc(2);
tv.v_type = VAR_LIST;
tv.vval.v_list = sub_l;
tv_item.v_type = VAR_LIST;
tv_item.vval.v_list = sub_l;
tv_list_ref(sub_l);
tv_list_append_owned_tv(sub_l, (typval_T) {
@ -11539,7 +11539,7 @@ static void dict_list(typval_T *const tv, typval_T *const rettv,
}
}
tv_list_append_owned_tv(rettv->vval.v_list, tv);
tv_list_append_owned_tv(rettv->vval.v_list, tv_item);
});
}
@ -14785,12 +14785,12 @@ static void f_setmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr)
list_T *const l = argvars[0].vval.v_list;
// To some extent make sure that we are dealing with a list from
// "getmatches()".
int i = 0;
int li_idx = 0;
TV_LIST_ITER_CONST(l, li, {
if (TV_LIST_ITEM_TV(li)->v_type != VAR_DICT
|| (d = TV_LIST_ITEM_TV(li)->vval.v_dict) == NULL) {
emsgf(_("E474: List item %d is either not a dictionary "
"or an empty one"), i);
"or an empty one"), li_idx);
return;
}
if (!(tv_dict_find(d, S_LEN("group")) != NULL
@ -14798,10 +14798,11 @@ static void f_setmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|| tv_dict_find(d, S_LEN("pos1")) != NULL)
&& tv_dict_find(d, S_LEN("priority")) != NULL
&& tv_dict_find(d, S_LEN("id")) != NULL)) {
emsgf(_("E474: List item %d is missing one of the required keys"), i);
emsgf(_("E474: List item %d is missing one of the required keys"),
li_idx);
return;
}
i++;
li_idx++;
});
clear_matches(curwin);

View File

@ -302,11 +302,11 @@ int encode_read_from_list(ListReaderState *const state, char *const buf,
const size_t len_ = (len); \
ga_grow(gap, (int) (2 + len_ + memcnt(buf_, '\'', len_))); \
ga_append(gap, '\''); \
for (size_t i = 0; i < len_; i++) { \
if (buf_[i] == '\'') { \
for (size_t i_ = 0; i_ < len_; i_++) { \
if (buf_[i_] == '\'') { \
ga_append(gap, '\''); \
} \
ga_append(gap, buf_[i]); \
ga_append(gap, buf_[i_]); \
} \
ga_append(gap, '\''); \
} \

View File

@ -2130,9 +2130,9 @@ void ex_listdo(exarg_T *eap)
// Remember the number of the next listed buffer, in case
// ":bwipe" is used or autocommands do something strange.
next_fnum = -1;
for (buf_T *buf = curbuf->b_next; buf != NULL; buf = buf->b_next) {
if (buf->b_p_bl) {
next_fnum = buf->b_fnum;
for (buf_T *bp = curbuf->b_next; bp != NULL; bp = bp->b_next) {
if (bp->b_p_bl) {
next_fnum = bp->b_fnum;
break;
}
}

View File

@ -5997,9 +5997,8 @@ void do_autocmd(char_u *arg_in, int forceit)
char_u *pat;
char_u *envpat = NULL;
char_u *cmd;
event_T event;
int need_free = FALSE;
int nested = FALSE;
int need_free = false;
int nested = false;
int group;
if (*arg == '|') {
@ -6082,7 +6081,7 @@ void do_autocmd(char_u *arg_in, int forceit)
last_event = (event_T)-1; // for listing the event name
last_group = AUGROUP_ERROR; // for listing the group name
if (*arg == '*' || *arg == NUL || *arg == '|') {
for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
for (event_T event = (event_T)0; (int)event < (int)NUM_EVENTS;
event = (event_T)((int)event + 1)) {
if (do_autocmd_event(event, pat, nested, cmd, forceit, group) == FAIL) {
break;

View File

@ -781,7 +781,6 @@ static void command_line_scan(mparm_T *parmp)
bool had_minmin = false; // found "--" argument
int want_argument; // option argument with argument
int c;
char_u *p = NULL;
long n;
argc--;
@ -1227,7 +1226,7 @@ scripterror:
// Add the file to the global argument list.
ga_grow(&global_alist.al_ga, 1);
p = vim_strsave((char_u *)argv[0]);
char_u *p = vim_strsave((char_u *)argv[0]);
if (parmp->diff_mode && os_isdir(p) && GARGCOUNT > 0
&& !os_isdir(alist_name(&GARGLIST[0]))) {

View File

@ -203,7 +203,7 @@ open_line (
char_u *ptr;
char_u last_char;
pos_T old_cursor = curwin->w_cursor;
old_cursor = curwin->w_cursor;
ptr = saved_line;
if (flags & OPENLINE_DO_COM)
lead_len = get_leader_len(ptr, NULL, FALSE, TRUE);

View File

@ -495,8 +495,8 @@ static void broadcast_event(const char *name, Array args)
kv_size(subscribed));
for (size_t i = 0; i < kv_size(subscribed); i++) {
Channel *channel = kv_A(subscribed, i);
channel_write(channel, buffer);
Channel *c = kv_A(subscribed, i);
channel_write(c, buffer);
}
end:

View File

@ -2670,7 +2670,6 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
colnr_T vcol;
int delcount;
int incr = 0;
long j;
struct block_def bd;
char_u **y_array = NULL;
long nr_lines = 0;
@ -2840,16 +2839,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
}
if (curbuf->terminal) {
for (int i = 0; i < count; i++) { // -V756
// feed the lines to the terminal
for (size_t j = 0; j < y_size; j++) {
if (j) {
// terminate the previous line
terminal_send(curbuf->terminal, "\n", 1);
}
terminal_send(curbuf->terminal, (char *)y_array[j], STRLEN(y_array[j]));
}
}
terminal_paste(count, y_array, y_size);
return;
}
@ -3035,12 +3025,14 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
yanklen = (int)STRLEN(y_array[i]);
/* calculate number of spaces required to fill right side of block*/
// calculate number of spaces required to fill right side of block
spaces = y_width + 1;
for (j = 0; j < yanklen; j++)
for (long j = 0; j < yanklen; j++) {
spaces -= lbr_chartabsize(NULL, &y_array[i][j], 0);
if (spaces < 0)
}
if (spaces < 0) {
spaces = 0;
}
// insert the new text
totlen = (size_t)(count * (yanklen + spaces)
@ -3050,21 +3042,21 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
ptr = newp;
memmove(ptr, oldp, (size_t)bd.textcol);
ptr += bd.textcol;
/* may insert some spaces before the new text */
// may insert some spaces before the new text
memset(ptr, ' ', (size_t)bd.startspaces);
ptr += bd.startspaces;
/* insert the new text */
for (j = 0; j < count; ++j) {
// insert the new text
for (long j = 0; j < count; j++) {
memmove(ptr, y_array[i], (size_t)yanklen);
ptr += yanklen;
/* insert block's trailing spaces only if there's text behind */
// insert block's trailing spaces only if there's text behind
if ((j < count - 1 || !shortline) && spaces) {
memset(ptr, ' ', (size_t)spaces);
ptr += spaces;
}
}
/* may insert some spaces after the new text */
// may insert some spaces after the new text
memset(ptr, ' ', (size_t)bd.endspaces);
ptr += bd.endspaces;
// move the text after the cursor to the end of the line.
@ -5697,12 +5689,12 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet)
// Timestamp is not saved for clipboard registers because clipboard registers
// are not saved in the ShaDa file.
int i = 0;
size_t tv_idx = 0;
TV_LIST_ITER_CONST(lines, li, {
if (TV_LIST_ITEM_TV(li)->v_type != VAR_STRING) {
goto err;
}
reg->y_array[i++] = (char_u *)xstrdupnul(
reg->y_array[tv_idx++] = (char_u *)xstrdupnul(
(const char *)TV_LIST_ITEM_TV(li)->vval.v_string);
});

View File

@ -925,11 +925,11 @@ restofline:
return QF_FAIL;
}
if (*fields->errmsg) {
size_t len = STRLEN(qfprev->qf_text);
size_t textlen = STRLEN(qfprev->qf_text);
qfprev->qf_text = xrealloc(qfprev->qf_text,
len + STRLEN(fields->errmsg) + 2);
qfprev->qf_text[len] = '\n';
STRCPY(qfprev->qf_text + len + 1, fields->errmsg);
textlen + STRLEN(fields->errmsg) + 2);
qfprev->qf_text[textlen] = '\n';
STRCPY(qfprev->qf_text + textlen + 1, fields->errmsg);
}
if (qfprev->qf_nr == -1) {
qfprev->qf_nr = fields->enr;

View File

@ -4006,23 +4006,23 @@ win_line (
draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
}
int attr = base_attr;
int col_attr = base_attr;
if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol) {
attr = cuc_attr;
col_attr = cuc_attr;
} else if (draw_color_col && VCOL_HLC == *color_cols) {
attr = mc_attr;
col_attr = mc_attr;
}
if (do_virttext) {
attr = hl_combine_attr(attr, virt_attr);
col_attr = hl_combine_attr(col_attr, virt_attr);
}
attr = hl_combine_attr(attr, line_attr);
col_attr = hl_combine_attr(col_attr, line_attr);
linebuf_attr[off] = attr;
linebuf_attr[off] = col_attr;
if (cells == 2) {
linebuf_attr[off+1] = attr;
linebuf_attr[off+1] = col_attr;
}
off += cells * col_stride;
@ -5200,9 +5200,9 @@ win_redr_custom (
curattr = attr;
p = buf;
for (n = 0; hltab[n].start != NULL; n++) {
int len = (int)(hltab[n].start - p);
grid_puts_len(&default_grid, p, len, row, col, curattr);
col += vim_strnsize(p, len);
int textlen = (int)(hltab[n].start - p);
grid_puts_len(&default_grid, p, textlen, row, col, curattr);
col += vim_strnsize(p, textlen);
p = hltab[n].start;
if (hltab[n].userhl == 0)

View File

@ -3475,53 +3475,55 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader,
} \
tgt = proc(obj.via.attr); \
} while (0)
#define CHECK_KEY_IS_STR(entry_name) \
if (unpacked.data.via.map.ptr[i].key.type != MSGPACK_OBJECT_STR) { \
#define CHECK_KEY_IS_STR(un, entry_name) \
if (un.data.via.map.ptr[i].key.type != MSGPACK_OBJECT_STR) { \
emsgf(_(READERR(entry_name, "has key which is not a string")), \
initial_fpos); \
CLEAR_GA_AND_ERROR_OUT(ad_ga); \
} else if (unpacked.data.via.map.ptr[i].key.via.str.size == 0) { \
} else if (un.data.via.map.ptr[i].key.via.str.size == 0) { \
emsgf(_(READERR(entry_name, "has empty key")), initial_fpos); \
CLEAR_GA_AND_ERROR_OUT(ad_ga); \
}
#define CHECKED_KEY(entry_name, name, error_desc, tgt, condition, attr, proc) \
#define CHECKED_KEY(un, entry_name, name, error_desc, tgt, condition, attr, \
proc) \
else if (CHECK_KEY( /* NOLINT(readability/braces) */ \
unpacked.data.via.map.ptr[i].key, name)) { \
un.data.via.map.ptr[i].key, name)) { \
CHECKED_ENTRY( \
condition, "has " name " key value " error_desc, \
entry_name, unpacked.data.via.map.ptr[i].val, \
entry_name, un.data.via.map.ptr[i].val, \
tgt, attr, proc); \
}
#define TYPED_KEY(entry_name, name, type_name, tgt, objtype, attr, proc) \
#define TYPED_KEY(un, entry_name, name, type_name, tgt, objtype, attr, proc) \
CHECKED_KEY( \
entry_name, name, "which is not " type_name, tgt, \
unpacked.data.via.map.ptr[i].val.type == MSGPACK_OBJECT_##objtype, \
un, entry_name, name, "which is not " type_name, tgt, \
un.data.via.map.ptr[i].val.type == MSGPACK_OBJECT_##objtype, \
attr, proc)
#define BOOLEAN_KEY(entry_name, name, tgt) \
TYPED_KEY(entry_name, name, "a boolean", tgt, BOOLEAN, boolean, ID)
#define STRING_KEY(entry_name, name, tgt) \
TYPED_KEY(entry_name, name, "a binary", tgt, BIN, bin, BINDUP)
#define CONVERTED_STRING_KEY(entry_name, name, tgt) \
TYPED_KEY(entry_name, name, "a binary", tgt, BIN, bin, BIN_CONVERTED)
#define INT_KEY(entry_name, name, tgt, proc) \
#define BOOLEAN_KEY(un, entry_name, name, tgt) \
TYPED_KEY(un, entry_name, name, "a boolean", tgt, BOOLEAN, boolean, ID)
#define STRING_KEY(un, entry_name, name, tgt) \
TYPED_KEY(un, entry_name, name, "a binary", tgt, BIN, bin, BINDUP)
#define CONVERTED_STRING_KEY(un, entry_name, name, tgt) \
TYPED_KEY(un, entry_name, name, "a binary", tgt, BIN, bin, \
BIN_CONVERTED)
#define INT_KEY(un, entry_name, name, tgt, proc) \
CHECKED_KEY( \
entry_name, name, "which is not an integer", tgt, \
((unpacked.data.via.map.ptr[i].val.type \
un, entry_name, name, "which is not an integer", tgt, \
((un.data.via.map.ptr[i].val.type \
== MSGPACK_OBJECT_POSITIVE_INTEGER) \
|| (unpacked.data.via.map.ptr[i].val.type \
|| (un.data.via.map.ptr[i].val.type \
== MSGPACK_OBJECT_NEGATIVE_INTEGER)), \
i64, proc)
#define INTEGER_KEY(entry_name, name, tgt) \
INT_KEY(entry_name, name, tgt, TOINT)
#define LONG_KEY(entry_name, name, tgt) \
INT_KEY(entry_name, name, tgt, TOLONG)
#define ADDITIONAL_KEY \
#define INTEGER_KEY(un, entry_name, name, tgt) \
INT_KEY(un, entry_name, name, tgt, TOINT)
#define LONG_KEY(un, entry_name, name, tgt) \
INT_KEY(un, entry_name, name, tgt, TOLONG)
#define ADDITIONAL_KEY(un) \
else { /* NOLINT(readability/braces) */ \
ga_grow(&ad_ga, 1); \
memcpy(((char *)ad_ga.ga_data) + ((size_t) ad_ga.ga_len \
* sizeof(*unpacked.data.via.map.ptr)), \
unpacked.data.via.map.ptr + i, \
sizeof(*unpacked.data.via.map.ptr)); \
memcpy(((char *)ad_ga.ga_data) + ((size_t)ad_ga.ga_len \
* sizeof(*un.data.via.map.ptr)), \
un.data.via.map.ptr + i, \
sizeof(*un.data.via.map.ptr)); \
ad_ga.ga_len++; \
}
#define CONVERTED(str, len) (xmemdupz((str), (len)))
@ -3726,28 +3728,29 @@ shada_read_next_item_start:
garray_T ad_ga;
ga_init(&ad_ga, sizeof(*(unpacked.data.via.map.ptr)), 1);
for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
CHECK_KEY_IS_STR("search pattern")
BOOLEAN_KEY("search pattern", SEARCH_KEY_MAGIC,
CHECK_KEY_IS_STR(unpacked, "search pattern")
BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_MAGIC,
entry->data.search_pattern.magic)
BOOLEAN_KEY("search pattern", SEARCH_KEY_SMARTCASE,
BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_SMARTCASE,
entry->data.search_pattern.smartcase)
BOOLEAN_KEY("search pattern", SEARCH_KEY_HAS_LINE_OFFSET,
BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_HAS_LINE_OFFSET,
entry->data.search_pattern.has_line_offset)
BOOLEAN_KEY("search pattern", SEARCH_KEY_PLACE_CURSOR_AT_END,
BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_PLACE_CURSOR_AT_END,
entry->data.search_pattern.place_cursor_at_end)
BOOLEAN_KEY("search pattern", SEARCH_KEY_IS_LAST_USED,
BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_IS_LAST_USED,
entry->data.search_pattern.is_last_used)
BOOLEAN_KEY("search pattern", SEARCH_KEY_IS_SUBSTITUTE_PATTERN,
BOOLEAN_KEY(unpacked, "search pattern",
SEARCH_KEY_IS_SUBSTITUTE_PATTERN,
entry->data.search_pattern.is_substitute_pattern)
BOOLEAN_KEY("search pattern", SEARCH_KEY_HIGHLIGHTED,
BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_HIGHLIGHTED,
entry->data.search_pattern.highlighted)
BOOLEAN_KEY("search pattern", SEARCH_KEY_BACKWARD,
BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_BACKWARD,
entry->data.search_pattern.search_backward)
INTEGER_KEY("search pattern", SEARCH_KEY_OFFSET,
INTEGER_KEY(unpacked, "search pattern", SEARCH_KEY_OFFSET,
entry->data.search_pattern.offset)
CONVERTED_STRING_KEY("search pattern", SEARCH_KEY_PAT,
CONVERTED_STRING_KEY(unpacked, "search pattern", SEARCH_KEY_PAT,
entry->data.search_pattern.pat)
ADDITIONAL_KEY
ADDITIONAL_KEY(unpacked)
}
if (entry->data.search_pattern.pat == NULL) {
emsgf(_(READERR("search pattern", "has no pattern")), initial_fpos);
@ -3768,7 +3771,7 @@ shada_read_next_item_start:
garray_T ad_ga;
ga_init(&ad_ga, sizeof(*(unpacked.data.via.map.ptr)), 1);
for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
CHECK_KEY_IS_STR("mark")
CHECK_KEY_IS_STR(unpacked, "mark")
if (CHECK_KEY(unpacked.data.via.map.ptr[i].key, KEY_NAME_CHAR)) {
if (type_u64 == kSDItemJump || type_u64 == kSDItemChange) {
emsgf(_(READERR("mark", "has n key which is only valid for "
@ -3782,10 +3785,10 @@ shada_read_next_item_start:
"mark", unpacked.data.via.map.ptr[i].val,
entry->data.filemark.name, u64, TOCHAR);
}
LONG_KEY("mark", KEY_LNUM, entry->data.filemark.mark.lnum)
INTEGER_KEY("mark", KEY_COL, entry->data.filemark.mark.col)
STRING_KEY("mark", KEY_FILE, entry->data.filemark.fname)
ADDITIONAL_KEY
LONG_KEY(unpacked, "mark", KEY_LNUM, entry->data.filemark.mark.lnum)
INTEGER_KEY(unpacked, "mark", KEY_COL, entry->data.filemark.mark.col)
STRING_KEY(unpacked, "mark", KEY_FILE, entry->data.filemark.fname)
ADDITIONAL_KEY(unpacked)
}
if (entry->data.filemark.fname == NULL) {
emsgf(_(READERR("mark", "is missing file name")), initial_fpos);
@ -3810,7 +3813,7 @@ shada_read_next_item_start:
garray_T ad_ga;
ga_init(&ad_ga, sizeof(*(unpacked.data.via.map.ptr)), 1);
for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
CHECK_KEY_IS_STR("register")
CHECK_KEY_IS_STR(unpacked, "register")
if (CHECK_KEY(unpacked.data.via.map.ptr[i].key,
REG_KEY_CONTENTS)) {
if (unpacked.data.via.map.ptr[i].val.type != MSGPACK_OBJECT_ARRAY) {
@ -3828,8 +3831,8 @@ shada_read_next_item_start:
}
const msgpack_object_array arr =
unpacked.data.via.map.ptr[i].val.via.array;
for (size_t i = 0; i < arr.size; i++) {
if (arr.ptr[i].type != MSGPACK_OBJECT_BIN) {
for (size_t j = 0; j < arr.size; j++) {
if (arr.ptr[j].type != MSGPACK_OBJECT_BIN) {
emsgf(_(READERR("register", "has " REG_KEY_CONTENTS " array "
"with non-binary value")), initial_fpos);
CLEAR_GA_AND_ERROR_OUT(ad_ga);
@ -3837,18 +3840,19 @@ shada_read_next_item_start:
}
entry->data.reg.contents_size = arr.size;
entry->data.reg.contents = xmalloc(arr.size * sizeof(char *));
for (size_t i = 0; i < arr.size; i++) {
entry->data.reg.contents[i] = BIN_CONVERTED(arr.ptr[i].via.bin);
for (size_t j = 0; j < arr.size; j++) {
entry->data.reg.contents[j] = BIN_CONVERTED(arr.ptr[j].via.bin);
}
}
BOOLEAN_KEY("register", REG_KEY_UNNAMED, entry->data.reg.is_unnamed)
TYPED_KEY("register", REG_KEY_TYPE, "an unsigned integer",
BOOLEAN_KEY(unpacked, "register", REG_KEY_UNNAMED,
entry->data.reg.is_unnamed)
TYPED_KEY(unpacked, "register", REG_KEY_TYPE, "an unsigned integer",
entry->data.reg.type, POSITIVE_INTEGER, u64, TOU8)
TYPED_KEY("register", KEY_NAME_CHAR, "an unsigned integer",
TYPED_KEY(unpacked, "register", KEY_NAME_CHAR, "an unsigned integer",
entry->data.reg.name, POSITIVE_INTEGER, u64, TOCHAR)
TYPED_KEY("register", REG_KEY_WIDTH, "an unsigned integer",
TYPED_KEY(unpacked, "register", REG_KEY_WIDTH, "an unsigned integer",
entry->data.reg.width, POSITIVE_INTEGER, u64, TOSIZE)
ADDITIONAL_KEY
ADDITIONAL_KEY(unpacked)
}
if (entry->data.reg.contents == NULL) {
emsgf(_(READERR("register", "has missing " REG_KEY_CONTENTS " array")),
@ -3990,8 +3994,7 @@ shada_read_next_item_start:
.data = unpacked.data.via.array.ptr[i],
};
{
msgpack_unpacked unpacked = unpacked_2;
if (unpacked.data.type != MSGPACK_OBJECT_MAP) {
if (unpacked_2.data.type != MSGPACK_OBJECT_MAP) {
emsgf(_(RERR "Error while reading ShaDa file: "
"buffer list at position %" PRIu64 " "
"contains entry that is not a dictionary"),
@ -4000,21 +4003,23 @@ shada_read_next_item_start:
}
entry->data.buffer_list.buffers[i].pos = default_pos;
garray_T ad_ga;
ga_init(&ad_ga, sizeof(*(unpacked.data.via.map.ptr)), 1);
ga_init(&ad_ga, sizeof(*(unpacked_2.data.via.map.ptr)), 1);
{
// XXX: Temporarily reassign `i` because the macros depend on it.
const size_t j = i;
{
for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
CHECK_KEY_IS_STR("buffer list entry")
LONG_KEY("buffer list entry", KEY_LNUM,
for (i = 0; i < unpacked_2.data.via.map.size; i++) {
CHECK_KEY_IS_STR(unpacked_2, "buffer list entry")
LONG_KEY(unpacked_2, "buffer list entry", KEY_LNUM,
entry->data.buffer_list.buffers[j].pos.lnum)
INTEGER_KEY("buffer list entry", KEY_COL,
INTEGER_KEY(unpacked_2, "buffer list entry", KEY_COL,
entry->data.buffer_list.buffers[j].pos.col)
STRING_KEY("buffer list entry", KEY_FILE,
STRING_KEY(unpacked_2, "buffer list entry", KEY_FILE,
entry->data.buffer_list.buffers[j].fname)
ADDITIONAL_KEY
ADDITIONAL_KEY(unpacked_2)
}
}
i = j; // XXX: Restore `i`.
}
if (entry->data.buffer_list.buffers[i].pos.lnum <= 0) {
emsgf(_(RERR "Error while reading ShaDa file: "

View File

@ -2112,9 +2112,9 @@ char_u *did_set_spelllang(win_T *wp)
}
if (region_mask != 0) {
langp_T *p = GA_APPEND_VIA_PTR(langp_T, &ga);
p->lp_slang = slang;
p->lp_region = region_mask;
langp_T *p_ = GA_APPEND_VIA_PTR(langp_T, &ga);
p_->lp_slang = slang;
p_->lp_region = region_mask;
use_midword(slang, wp);
if (slang->sl_nobreak)
@ -2190,11 +2190,11 @@ char_u *did_set_spelllang(win_T *wp)
}
if (region_mask != 0) {
langp_T *p = GA_APPEND_VIA_PTR(langp_T, &ga);
p->lp_slang = slang;
p->lp_sallang = NULL;
p->lp_replang = NULL;
p->lp_region = region_mask;
langp_T *p_ = GA_APPEND_VIA_PTR(langp_T, &ga);
p_->lp_slang = slang;
p_->lp_sallang = NULL;
p_->lp_replang = NULL;
p_->lp_region = region_mask;
use_midword(slang, wp);
}

View File

@ -4311,8 +4311,8 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
qsort(gap->ga_data, (size_t)gap->ga_len,
sizeof(fromto_T), rep_compare);
int i = round == 1 ? SN_REP : (round == 2 ? SN_SAL : SN_REPSAL);
putc(i, fd); // <sectionID>
int sect_id = round == 1 ? SN_REP : (round == 2 ? SN_SAL : SN_REPSAL);
putc(sect_id, fd); // <sectionID>
// This is for making suggestions, section is not required.
putc(0, fd); // <sectionflags>

View File

@ -6463,7 +6463,7 @@ void do_highlight(const char *line, const bool forceit, const bool init)
// If no argument, list current highlighting.
if (ends_excmd((uint8_t)(*line))) {
for (int i = 1; i <= highlight_ga.ga_len && !got_int; i++) {
for (i = 1; i <= highlight_ga.ga_len && !got_int; i++) {
// TODO(brammool): only call when the group has attributes set
highlight_list_one(i);
}
@ -6569,8 +6569,8 @@ void do_highlight(const char *line, const bool forceit, const bool init)
restore_cterm_colors();
// Clear all default highlight groups and load the defaults.
for (int idx = 0; idx < highlight_ga.ga_len; idx++) {
highlight_clear(idx);
for (int j = 0; j < highlight_ga.ga_len; j++) {
highlight_clear(j);
}
init_highlight(true, true);
highlight_changed();

View File

@ -529,6 +529,20 @@ void terminal_send(Terminal *term, char *data, size_t size)
term->opts.write_cb(data, size, term->opts.data);
}
void terminal_paste(long count, char_u **y_array, size_t y_size)
{
for (int i = 0; i < count; i++) { // -V756
// feed the lines to the terminal
for (size_t j = 0; j < y_size; j++) {
if (j) {
// terminate the previous line
terminal_send(curbuf->terminal, "\n", 1);
}
terminal_send(curbuf->terminal, (char *)y_array[j], STRLEN(y_array[j]));
}
}
}
void terminal_flush_output(Terminal *term)
{
size_t len = vterm_output_read(term->vt, term->textbuf,

View File

@ -352,8 +352,8 @@ static bool handle_forced_escape(TermInput *input)
return false;
}
static void read_cb(Stream *stream, RBuffer *buf, size_t c, void *data,
bool eof)
static void read_cb(Stream *stream, RBuffer *buf, size_t count_, void *data,
bool eof)
{
TermInput *input = data;

View File

@ -51,10 +51,10 @@
static UI *uis[MAX_UI_COUNT];
static bool ui_ext[kUIExtCount] = { 0 };
static size_t ui_count = 0;
static int row = 0, col = 0;
static int ui_mode_idx = SHAPE_IDX_N;
static int cursor_row = 0, cursor_col = 0;
static bool pending_cursor_update = false;
static int busy = 0;
static int mode_idx = SHAPE_IDX_N;
static bool pending_mode_info_update = false;
static bool pending_mode_update = false;
static handle_T cursor_grid_handle = DEFAULT_GRID_HANDLE;
@ -189,12 +189,12 @@ void ui_refresh(void)
UI *ui = uis[i];
width = MIN(ui->width, width);
height = MIN(ui->height, height);
for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
ext_widgets[i] &= ui->ui_ext[i];
for (UIExtension j = 0; (int)j < kUIExtCount; j++) {
ext_widgets[j] &= ui->ui_ext[j];
}
}
row = col = 0;
cursor_row = cursor_col = 0;
pending_cursor_update = true;
for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
@ -327,9 +327,9 @@ void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol,
(const sattr_T *)grid->attrs + off);
if (p_wd) { // 'writedelay': flush & delay each time.
int old_row = row, old_col = col;
int old_row = cursor_row, old_col = cursor_col;
handle_T old_grid = cursor_grid_handle;
// If'writedelay is active, we set the cursor to highlight what was drawn
// If 'writedelay' is active, set the cursor to indicate what was drawn.
ui_grid_cursor_goto(grid->handle, row, MIN(clearcol, (int)Columns-1));
ui_flush();
uint64_t wd = (uint64_t)labs(p_wd);
@ -345,12 +345,14 @@ void ui_cursor_goto(int new_row, int new_col)
void ui_grid_cursor_goto(handle_T grid_handle, int new_row, int new_col)
{
if (new_row == row && new_col == col && grid_handle == cursor_grid_handle) {
if (new_row == cursor_row
&& new_col == cursor_col
&& grid_handle == cursor_grid_handle) {
return;
}
row = new_row;
col = new_col;
cursor_row = new_row;
cursor_col = new_col;
cursor_grid_handle = grid_handle;
pending_cursor_update = true;
}
@ -362,12 +364,12 @@ void ui_mode_info_set(void)
int ui_current_row(void)
{
return row;
return cursor_row;
}
int ui_current_col(void)
{
return col;
return cursor_col;
}
void ui_flush(void)
@ -375,7 +377,7 @@ void ui_flush(void)
cmdline_ui_flush();
win_ui_flush();
if (pending_cursor_update) {
ui_call_grid_cursor_goto(cursor_grid_handle, row, col);
ui_call_grid_cursor_goto(cursor_grid_handle, cursor_row, cursor_col);
pending_cursor_update = false;
}
if (pending_mode_info_update) {
@ -386,8 +388,8 @@ void ui_flush(void)
pending_mode_info_update = false;
}
if (pending_mode_update) {
char *full_name = shape_table[mode_idx].full_name;
ui_call_mode_change(cstr_as_string(full_name), mode_idx);
char *full_name = shape_table[ui_mode_idx].full_name;
ui_call_mode_change(cstr_as_string(full_name), ui_mode_idx);
pending_mode_update = false;
}
ui_call_flush();
@ -403,8 +405,8 @@ void ui_cursor_shape(void)
}
int new_mode_idx = cursor_get_mode_idx();
if (new_mode_idx != mode_idx) {
mode_idx = new_mode_idx;
if (new_mode_idx != ui_mode_idx) {
ui_mode_idx = new_mode_idx;
pending_mode_update = true;
}
conceal_check_cursor_line();