From 7b952793d5c46e862a9cdec3d6ac4762370296ed Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 26 May 2022 04:49:25 +0200 Subject: [PATCH] refactor: missing parenthesis may cause unexpected problems (#17443) related vim-8.2.{4402,4639} --- .clang-format | 3 +- src/nvim/api/vim.c | 8 ++-- src/nvim/charset.c | 8 ++-- src/nvim/debugger.c | 2 +- src/nvim/edit.c | 4 +- src/nvim/eval.c | 6 +-- src/nvim/eval/decode.c | 6 +-- src/nvim/eval/encode.c | 40 ++++++++--------- src/nvim/eval/typval.c | 59 ++++++++++++------------- src/nvim/ex_docmd.c | 2 +- src/nvim/fileio.c | 6 +-- src/nvim/getchar.c | 2 +- src/nvim/map.c | 8 ++-- src/nvim/marktree.c | 2 +- src/nvim/regexp_nfa.c | 2 +- src/nvim/shada.c | 97 ++++++++++++++++++++++-------------------- src/nvim/spell.c | 2 +- src/nvim/strings.c | 2 +- 18 files changed, 132 insertions(+), 127 deletions(-) diff --git a/.clang-format b/.clang-format index a37e2fdbd1..afb0df2e25 100644 --- a/.clang-format +++ b/.clang-format @@ -45,6 +45,7 @@ IncludeCategories: Priority: 1 SortPriority: 1 CaseSensitive: false +AlignConsecutiveMacros: AcrossEmptyLines IndentPPDirectives: AfterHash SpaceBeforeParens: ControlStatementsExceptControlMacros ForEachMacros: @@ -62,4 +63,4 @@ ForEachMacros: - RBUFFER_EACH_REVERSE - RBUFFER_UNTIL_EMPTY - RBUFFER_UNTIL_FULL - - kl_iter \ No newline at end of file + - kl_iter diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 7ca0912f82..dd0b75bbfb 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1931,13 +1931,13 @@ static void write_msg(String message, bool to_err) static char out_line_buf[LINE_BUFFER_SIZE], err_line_buf[LINE_BUFFER_SIZE]; #define PUSH_CHAR(i, pos, line_buf, msg) \ - if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) { \ - line_buf[pos] = NUL; \ + if (message.data[i] == NL || (pos) == LINE_BUFFER_SIZE - 1) { \ + (line_buf)[pos] = NUL; \ msg(line_buf); \ - pos = 0; \ + (pos) = 0; \ continue; \ } \ - line_buf[pos++] = message.data[i]; + (line_buf)[(pos)++] = message.data[i]; no_wait_return++; for (uint32_t i = 0; i < message.size; i++) { diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 649407ce12..e20c0e3f3f 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -1556,10 +1556,10 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len, cons } \ const uvarnumber_T digit = (uvarnumber_T)(conv); \ /* avoid ubsan error for overflow */ \ - if (un < UVARNUMBER_MAX / base \ - || (un == UVARNUMBER_MAX / base \ - && (base != 10 || digit <= UVARNUMBER_MAX % 10))) { \ - un = base * un + digit; \ + if (un < UVARNUMBER_MAX / (base) \ + || (un == UVARNUMBER_MAX / (base) \ + && ((base) != 10 || digit <= UVARNUMBER_MAX % 10))) { \ + un = (base) * un + digit; \ } else { \ un = UVARNUMBER_MAX; \ } \ diff --git a/src/nvim/debugger.c b/src/nvim/debugger.c index 16e96431e2..30d6ea2505 100644 --- a/src/nvim/debugger.c +++ b/src/nvim/debugger.c @@ -444,7 +444,7 @@ bool dbg_check_skipped(exarg_T *eap) static garray_T dbg_breakp = { 0, 0, sizeof(struct debuggy), 4, NULL }; #define BREAKP(idx) (((struct debuggy *)dbg_breakp.ga_data)[idx]) -#define DEBUGGY(gap, idx) (((struct debuggy *)gap->ga_data)[idx]) +#define DEBUGGY(gap, idx) (((struct debuggy *)(gap)->ga_data)[idx]) static int last_breakp = 0; // nr of last defined breakpoint // Profiling uses file and func names similar to breakpoints. diff --git a/src/nvim/edit.c b/src/nvim/edit.c index eebdf3f0d6..41fa34c31e 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2351,9 +2351,9 @@ static int ins_compl_add(char_u *const str, int len, char_u *const fname, } #define FREE_CPTEXT(cptext, cptext_allocated) \ do { \ - if (cptext != NULL && cptext_allocated) { \ + if ((cptext) != NULL && (cptext_allocated)) { \ for (size_t i = 0; i < CPT_COUNT; i++) { \ - xfree(cptext[i]); \ + xfree((cptext)[i]); \ } \ } \ } while (0) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 792c8d3aec..02dc5ec954 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -124,13 +124,13 @@ typedef struct { #define VV(idx, name, type, flags) \ [idx] = { \ - .vv_name = name, \ + .vv_name = (name), \ .vv_di = { \ - .di_tv = { .v_type = type }, \ + .di_tv = { .v_type = (type) }, \ .di_flags = 0, \ .di_key = { 0 }, \ }, \ - .vv_flags = flags, \ + .vv_flags = (flags), \ } #define VIMVAR_KEY_LEN 16 // Maximum length of the key of v:variables diff --git a/src/nvim/eval/decode.c b/src/nvim/eval/decode.c index 2dd18c0942..7b975ce775 100644 --- a/src/nvim/eval/decode.c +++ b/src/nvim/eval/decode.c @@ -414,9 +414,9 @@ static inline int parse_json_string(const char *const buf, const size_t buf_len, bool hasnul = false; #define PUT_FST_IN_PAIR(fst_in_pair, str_end) \ do { \ - if (fst_in_pair != 0) { \ - str_end += utf_char2bytes(fst_in_pair, str_end); \ - fst_in_pair = 0; \ + if ((fst_in_pair) != 0) { \ + (str_end) += utf_char2bytes(fst_in_pair, (str_end)); \ + (fst_in_pair) = 0; \ } \ } while (0) for (const char *t = s; t < p; t++) { diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index de93ddc70d..090939666d 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -293,8 +293,8 @@ int encode_read_from_list(ListReaderState *const state, char *const buf, const s #define TYPVAL_ENCODE_CONV_STRING(tv, buf, len) \ do { \ - const char *const buf_ = (const char *)buf; \ - if (buf == NULL) { \ + const char *const buf_ = (const char *)(buf); \ + if ((buf) == NULL) { \ ga_concat(gap, "''"); \ } else { \ const size_t len_ = (len); \ @@ -383,14 +383,14 @@ int encode_read_from_list(ListReaderState *const state, char *const buf, const s #define TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS(tv, len) \ do { \ - if (len != 0) { \ + if ((len) != 0) { \ ga_concat(gap, ", "); \ } \ } while (0) #define TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, len) \ do { \ - if ((ptrdiff_t)len != -1) { \ + if ((ptrdiff_t)(len) != -1) { \ ga_concat(gap, ", "); \ } \ } while (0) @@ -452,12 +452,12 @@ int encode_read_from_list(ListReaderState *const state, char *const buf, const s size_t backref = 0; \ for (; backref < kv_size(*mpstack); backref++) { \ const MPConvStackVal mpval = kv_A(*mpstack, backref); \ - if (mpval.type == conv_type) { \ - if (conv_type == kMPConvDict) { \ + if (mpval.type == (conv_type)) { \ + if ((conv_type) == kMPConvDict) { \ if ((void *)mpval.data.d.dict == (void *)(val)) { \ break; \ } \ - } else if (conv_type == kMPConvList) { \ + } else if ((conv_type) == kMPConvList) { \ if ((void *)mpval.data.l.list == (void *)(val)) { \ break; \ } \ @@ -487,19 +487,19 @@ int encode_read_from_list(ListReaderState *const state, char *const buf, const s size_t backref = 0; \ for (; backref < kv_size(*mpstack); backref++) { \ const MPConvStackVal mpval = kv_A(*mpstack, backref); \ - if (mpval.type == conv_type) { \ - if (conv_type == kMPConvDict) { \ - if ((void *)mpval.data.d.dict == (void *)val) { \ + if (mpval.type == (conv_type)) { \ + if ((conv_type) == kMPConvDict) { \ + if ((void *)mpval.data.d.dict == (void *)(val)) { \ break; \ } \ - } else if (conv_type == kMPConvList) { \ - if ((void *)mpval.data.l.list == (void *)val) { \ + } else if ((conv_type) == kMPConvList) { \ + if ((void *)mpval.data.l.list == (void *)(val)) { \ break; \ } \ } \ } \ } \ - if (conv_type == kMPConvDict) { \ + if ((conv_type) == kMPConvDict) { \ vim_snprintf(ebuf, ARRAY_SIZE(ebuf), "{...@%zu}", backref); \ } else { \ vim_snprintf(ebuf, ARRAY_SIZE(ebuf), "[...@%zu]", backref); \ @@ -609,7 +609,7 @@ static inline int convert_to_json_string(garray_T *const gap, const char *const // This is done to make resulting values displayable on screen also not from // Neovim. #define ENCODE_RAW(ch) \ - (ch >= 0x20 && utf_printable(ch)) + ((ch) >= 0x20 && utf_printable(ch)) for (size_t i = 0; i < utf_len;) { const int ch = utf_ptr2char(utf_buf + i); const size_t shift = (ch == 0 ? 1 : ((size_t)utf_ptr2len(utf_buf + i))); @@ -788,7 +788,7 @@ bool encode_check_json_key(const typval_T *const tv) #undef TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK #define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK(label, key) \ do { \ - if (!encode_check_json_key(&key)) { \ + if (!encode_check_json_key(&(key))) { \ emsg(_("E474: Invalid key in special dictionary")); \ goto label; \ } \ @@ -911,7 +911,7 @@ char *encode_tv2json(typval_T *tv, size_t *len) #define TYPVAL_ENCODE_CONV_STRING(tv, buf, len) \ do { \ - if (buf == NULL) { \ + if ((buf) == NULL) { \ msgpack_pack_bin(packer, 0); \ } else { \ const size_t len_ = (len); \ @@ -922,7 +922,7 @@ char *encode_tv2json(typval_T *tv, size_t *len) #define TYPVAL_ENCODE_CONV_STR_STRING(tv, buf, len) \ do { \ - if (buf == NULL) { \ + if ((buf) == NULL) { \ msgpack_pack_str(packer, 0); \ } else { \ const size_t len_ = (len); \ @@ -933,11 +933,11 @@ char *encode_tv2json(typval_T *tv, size_t *len) #define TYPVAL_ENCODE_CONV_EXT_STRING(tv, buf, len, type) \ do { \ - if (buf == NULL) { \ - msgpack_pack_ext(packer, 0, (int8_t)type); \ + if ((buf) == NULL) { \ + msgpack_pack_ext(packer, 0, (int8_t)(type)); \ } else { \ const size_t len_ = (len); \ - msgpack_pack_ext(packer, len_, (int8_t)type); \ + msgpack_pack_ext(packer, len_, (int8_t)(type)); \ msgpack_pack_ext_body(packer, buf, len_); \ } \ } while (0) diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index de3d9bdf7f..2c76741891 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -879,9 +879,9 @@ void tv_list_reverse(list_T *const l) list_log(l, NULL, NULL, "reverse"); #define SWAP(a, b) \ do { \ - tmp = a; \ - a = b; \ - b = tmp; \ + tmp = (a); \ + (a) = (b); \ + (b) = tmp; \ } while (0) listitem_T *tmp; @@ -2262,36 +2262,36 @@ void tv_blob_copy(typval_T *const from, typval_T *const to) #define TYPVAL_ENCODE_CONV_NIL(tv) \ do { \ - tv->vval.v_special = kSpecialVarNull; \ - tv->v_lock = VAR_UNLOCKED; \ + (tv)->vval.v_special = kSpecialVarNull; \ + (tv)->v_lock = VAR_UNLOCKED; \ } while (0) #define TYPVAL_ENCODE_CONV_BOOL(tv, num) \ do { \ - tv->vval.v_bool = kBoolVarFalse; \ - tv->v_lock = VAR_UNLOCKED; \ + (tv)->vval.v_bool = kBoolVarFalse; \ + (tv)->v_lock = VAR_UNLOCKED; \ } while (0) #define TYPVAL_ENCODE_CONV_NUMBER(tv, num) \ do { \ - (void)num; \ - tv->vval.v_number = 0; \ - tv->v_lock = VAR_UNLOCKED; \ + (void)(num); \ + (tv)->vval.v_number = 0; \ + (tv)->v_lock = VAR_UNLOCKED; \ } while (0) #define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER(tv, num) #define TYPVAL_ENCODE_CONV_FLOAT(tv, flt) \ do { \ - tv->vval.v_float = 0; \ - tv->v_lock = VAR_UNLOCKED; \ + (tv)->vval.v_float = 0; \ + (tv)->v_lock = VAR_UNLOCKED; \ } while (0) #define TYPVAL_ENCODE_CONV_STRING(tv, buf, len) \ do { \ xfree(buf); \ - tv->vval.v_string = NULL; \ - tv->v_lock = VAR_UNLOCKED; \ + (tv)->vval.v_string = NULL; \ + (tv)->v_lock = VAR_UNLOCKED; \ } while (0) #define TYPVAL_ENCODE_CONV_STR_STRING(tv, buf, len) @@ -2300,9 +2300,9 @@ void tv_blob_copy(typval_T *const from, typval_T *const to) #define TYPVAL_ENCODE_CONV_BLOB(tv, blob, len) \ do { \ - tv_blob_unref(tv->vval.v_blob); \ - tv->vval.v_blob = NULL; \ - tv->v_lock = VAR_UNLOCKED; \ + tv_blob_unref((tv)->vval.v_blob); \ + (tv)->vval.v_blob = NULL; \ + (tv)->v_lock = VAR_UNLOCKED; \ } while (0) static inline int _nothing_conv_func_start(typval_T *const tv, char_u *const fun) @@ -2359,9 +2359,9 @@ static inline void _nothing_conv_func_end(typval_T *const tv, const int copyID) #define TYPVAL_ENCODE_CONV_EMPTY_LIST(tv) \ do { \ - tv_list_unref(tv->vval.v_list); \ - tv->vval.v_list = NULL; \ - tv->v_lock = VAR_UNLOCKED; \ + tv_list_unref((tv)->vval.v_list); \ + (tv)->vval.v_list = NULL; \ + (tv)->v_lock = VAR_UNLOCKED; \ } while (0) static inline void _nothing_conv_empty_dict(typval_T *const tv, dict_T **const dictp) @@ -2375,8 +2375,8 @@ static inline void _nothing_conv_empty_dict(typval_T *const tv, dict_T **const d } #define TYPVAL_ENCODE_CONV_EMPTY_DICT(tv, dict) \ do { \ - assert((void *)&dict != (void *)&TYPVAL_ENCODE_NODICT_VAR); \ - _nothing_conv_empty_dict(tv, ((dict_T **)&dict)); \ + assert((void *)&(dict) != (void *)&TYPVAL_ENCODE_NODICT_VAR); \ + _nothing_conv_empty_dict(tv, ((dict_T **)&(dict))); \ } while (0) static inline int _nothing_conv_real_list_after_start(typval_T *const tv, @@ -2397,7 +2397,7 @@ static inline int _nothing_conv_real_list_after_start(typval_T *const tv, #define TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START(tv, mpsv) \ do { \ - if (_nothing_conv_real_list_after_start(tv, &mpsv) != NOTDONE) { \ + if (_nothing_conv_real_list_after_start(tv, &(mpsv)) != NOTDONE) { \ goto typval_encode_stop_converting_one_item; \ } \ } while (0) @@ -2437,8 +2437,9 @@ static inline int _nothing_conv_real_dict_after_start(typval_T *const tv, dict_T #define TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START(tv, dict, mpsv) \ do { \ - if (_nothing_conv_real_dict_after_start(tv, (dict_T **)&dict, (void *)&TYPVAL_ENCODE_NODICT_VAR, \ - &mpsv) != NOTDONE) { \ + if (_nothing_conv_real_dict_after_start(tv, (dict_T **)&(dict), \ + (void *)&TYPVAL_ENCODE_NODICT_VAR, &(mpsv)) \ + != NOTDONE) { \ goto typval_encode_stop_converting_one_item; \ } \ } while (0) @@ -2457,7 +2458,7 @@ static inline void _nothing_conv_dict_end(typval_T *const tv, dict_T **const dic } } #define TYPVAL_ENCODE_CONV_DICT_END(tv, dict) \ - _nothing_conv_dict_end(tv, (dict_T **)&dict, \ + _nothing_conv_dict_end(tv, (dict_T **)&(dict), \ (void *)&TYPVAL_ENCODE_NODICT_VAR) #define TYPVAL_ENCODE_CONV_RECURSE(val, conv_type) @@ -2639,9 +2640,9 @@ void tv_item_lock(typval_T *const tv, const int deep, const bool lock, const boo // lock/unlock the item itself #define CHANGE_LOCK(lock, var) \ do { \ - var = ((VarLockStatus[]) { \ - [VAR_UNLOCKED] = (lock ? VAR_LOCKED : VAR_UNLOCKED), \ - [VAR_LOCKED] = (lock ? VAR_LOCKED : VAR_UNLOCKED), \ + (var) = ((VarLockStatus[]) { \ + [VAR_UNLOCKED] = ((lock) ? VAR_LOCKED : VAR_UNLOCKED), \ + [VAR_LOCKED] = ((lock) ? VAR_LOCKED : VAR_UNLOCKED), \ [VAR_FIXED] = VAR_FIXED, \ })[var]; \ } while (0) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 12fd72ba70..4b7958efa5 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -7425,7 +7425,7 @@ static void ex_goto(exarg_T *eap) /// Clear an argument list: free all file names and reset it to zero entries. void alist_clear(alist_T *al) { -#define FREE_AENTRY_FNAME(arg) xfree(arg->ae_fname) +#define FREE_AENTRY_FNAME(arg) xfree((arg)->ae_fname) GA_DEEP_CLEAR(&al->al_ga, aentry_T, FREE_AENTRY_FNAME); } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index e869a9a6de..8d8c10f823 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -2195,11 +2195,11 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en linenr_T lnum; long nchars; #define SET_ERRMSG_NUM(num, msg) \ - errnum = num, errmsg = msg, errmsgarg = 0 + errnum = (num), errmsg = (msg), errmsgarg = 0 #define SET_ERRMSG_ARG(msg, error) \ - errnum = NULL, errmsg = msg, errmsgarg = error + errnum = NULL, errmsg = (msg), errmsgarg = error #define SET_ERRMSG(msg) \ - errnum = NULL, errmsg = msg, errmsgarg = 0 + errnum = NULL, errmsg = (msg), errmsgarg = 0 const char *errnum = NULL; char *errmsg = NULL; int errmsgarg = 0; diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 7c8ac211ec..788e1113e2 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -3799,7 +3799,7 @@ bool map_to_exists(const char *const str, const char *const modechars, const boo #define MAPMODE(mode, modechars, chr, modeflags) \ do { \ if (strchr(modechars, chr) != NULL) { \ - mode |= modeflags; \ + (mode) |= (modeflags); \ } \ } while (0) MAPMODE(mode, modechars, 'n', MODE_NORMAL); diff --git a/src/nvim/map.c b/src/nvim/map.c index ece5135559..05ad113008 100644 --- a/src/nvim/map.c +++ b/src/nvim/map.c @@ -33,11 +33,11 @@ #define handle_T_eq kh_int_hash_equal #if defined(ARCH_64) -# define ptr_t_hash(key) uint64_t_hash((uint64_t)key) -# define ptr_t_eq(a, b) uint64_t_eq((uint64_t)a, (uint64_t)b) +# define ptr_t_hash(key) uint64_t_hash((uint64_t)(key)) +# define ptr_t_eq(a, b) uint64_t_eq((uint64_t)(a), (uint64_t)(b)) #elif defined(ARCH_32) -# define ptr_t_hash(key) uint32_t_hash((uint32_t)key) -# define ptr_t_eq(a, b) uint32_t_eq((uint32_t)a, (uint32_t)b) +# define ptr_t_hash(key) uint32_t_hash((uint32_t)(key)) +# define ptr_t_eq(a, b) uint32_t_eq((uint32_t)(a), (uint32_t)(b)) #endif #define INITIALIZER(T, U) T##_##U##_initializer diff --git a/src/nvim/marktree.c b/src/nvim/marktree.c index c29e540214..03340a99d6 100644 --- a/src/nvim/marktree.c +++ b/src/nvim/marktree.c @@ -58,7 +58,7 @@ #define ID_INCR (((uint64_t)1) << 2) -#define rawkey(itr) (itr->node->key[itr->i]) +#define rawkey(itr) ((itr)->node->key[(itr)->i]) static bool pos_leq(mtpos_t a, mtpos_t b) { diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 6f1b392ed9..d867b5db95 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -6027,7 +6027,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm #define ADD_STATE_IF_MATCH(state) \ if (result) { \ - add_state = state->out; \ + add_state = (state)->out; \ add_off = clen; \ } diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 84ab5190bf..2693cb0273 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -512,8 +512,8 @@ static inline void hmll_init(HMLList *const hmll, const size_t size) /// /// @return `for` cycle header (use `HMLL_FORALL(hmll, cur_entry) {body}`). #define HMLL_FORALL(hmll, cur_entry, code) \ - for (HMLListEntry *cur_entry = (hmll)->first; cur_entry != NULL; \ - cur_entry = cur_entry->next) { \ + for (HMLListEntry *(cur_entry) = (hmll)->first; (cur_entry) != NULL; \ + (cur_entry) = (cur_entry)->next) { \ code \ } \ @@ -1072,13 +1072,13 @@ static inline bool marks_equal(const pos_T a, const pos_T b) entry, fname_cond, free_func, fin_func, \ idxadj_func, afterfree_func) \ do { \ - const int jl_len = (int)jumps_size; \ + const int jl_len = (int)(jumps_size); \ int i; \ for (i = jl_len; i > 0; i--) { \ - const jumps_type jl_entry = jumps[i - 1]; \ - if (jl_entry.timestamp_attr <= entry.timestamp) { \ - if (marks_equal(jl_entry.mark_attr, entry.data.filemark.mark) \ - && fname_cond) { \ + const jumps_type jl_entry = (jumps)[i - 1]; \ + if (jl_entry.timestamp_attr <= (entry).timestamp) { \ + if (marks_equal(jl_entry.mark_attr, (entry).data.filemark.mark) \ + && (fname_cond)) { \ i = -1; \ } \ break; \ @@ -1086,30 +1086,30 @@ static inline bool marks_equal(const pos_T a, const pos_T b) } \ if (i > 0) { \ if (jl_len == JUMPLISTSIZE) { \ - free_func(jumps[0]); \ + free_func((jumps)[0]); \ i--; \ if (i > 0) { \ - memmove(&jumps[0], &jumps[1], sizeof(jumps[1]) * (size_t)i); \ + memmove(&(jumps)[0], &(jumps)[1], sizeof((jumps)[1]) * (size_t)i); \ } \ } else if (i != jl_len) { \ - memmove(&jumps[i + 1], &jumps[i], \ - sizeof(jumps[0]) * (size_t)(jl_len - i)); \ + memmove(&(jumps)[i + 1], &(jumps)[i], \ + sizeof((jumps)[0]) * (size_t)(jl_len - i)); \ } \ } else if (i == 0) { \ if (jl_len == JUMPLISTSIZE) { \ i = -1; \ } else if (jl_len > 0) { \ - memmove(&jumps[1], &jumps[0], sizeof(jumps[0]) * (size_t)jl_len); \ + memmove(&(jumps)[1], &(jumps)[0], sizeof((jumps)[0]) * (size_t)jl_len); \ } \ } \ if (i != -1) { \ - jumps[i] = fin_func(entry); \ + (jumps)[i] = fin_func(entry); \ if (jl_len < JUMPLISTSIZE) { \ - jumps_size++; \ + (jumps_size)++; \ } \ idxadj_func(i); \ } else { \ - shada_free_shada_entry(&entry); \ + shada_free_shada_entry(&(entry)); \ afterfree_func(entry); \ } \ } while (0) @@ -1304,7 +1304,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) } else { #define SDE_TO_XFMARK(entry) fm #define ADJUST_IDX(i) \ - if (curwin->w_jumplistidx >= i \ + if (curwin->w_jumplistidx >= (i) \ && curwin->w_jumplistidx + 1 <= curwin->w_jumplistlen) { \ curwin->w_jumplistidx++; \ } @@ -1547,7 +1547,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr } \ } while (0) #define CHECK_DEFAULT(entry, attr) \ - (sd_default_values[entry.type].data.attr == entry.data.attr) + (sd_default_values[(entry).type].data.attr == (entry).data.attr) #define ONE_IF_NOT_DEFAULT(entry, attr) \ ((size_t)(!CHECK_DEFAULT(entry, attr))) switch (entry.type) { @@ -1637,7 +1637,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr do { \ if (!CHECK_DEFAULT(entry, search_pattern.attr)) { \ PACK_STATIC_STR(name); \ - if (sd_default_values[entry.type].data.search_pattern.attr) { \ + if (sd_default_values[(entry).type].data.search_pattern.attr) { \ msgpack_pack_false(spacker); \ } else { \ msgpack_pack_true(spacker); \ @@ -2221,12 +2221,12 @@ static inline ShaDaWriteResult shada_read_when_writing(ShaDaReadDef *const sd_re } else { #define FREE_POSSIBLY_FREED_SHADA_ENTRY(entry) \ do { \ - if (entry.can_free_entry) { \ - shada_free_shada_entry(&entry.data); \ + if ((entry).can_free_entry) { \ + shada_free_shada_entry(&(entry).data); \ } \ } while (0) #define SDE_TO_PFSDE(entry) \ - ((PossiblyFreedShadaEntry) { .can_free_entry = true, .data = entry }) + ((PossiblyFreedShadaEntry) { .can_free_entry = true, .data = (entry) }) #define AFTERFREE_DUMMY(entry) #define DUMMY_IDX_ADJ(i) MERGE_JUMPS(filemarks->changes_size, filemarks->changes, @@ -2814,8 +2814,8 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef #define PACK_WMS_ARRAY(wms_array) \ do { \ for (size_t i_ = 0; i_ < ARRAY_SIZE(wms_array); i_++) { \ - if (wms_array[i_].data.type != kSDItemMissing) { \ - if (shada_pack_pfreed_entry(packer, wms_array[i_], max_kbyte) \ + if ((wms_array)[i_].data.type != kSDItemMissing) { \ + if (shada_pack_pfreed_entry(packer, (wms_array)[i_], max_kbyte) \ == kSDWriteFailed) { \ ret = kSDWriteFailed; \ goto shada_write_exit; \ @@ -2835,7 +2835,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef } #define PACK_WMS_ENTRY(wms_entry) \ do { \ - if (wms_entry.data.type != kSDItemMissing) { \ + if ((wms_entry).data.type != kSDItemMissing) { \ if (shada_pack_pfreed_entry(packer, wms_entry, max_kbyte) \ == kSDWriteFailed) { \ ret = kSDWriteFailed; \ @@ -3312,16 +3312,16 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const RERR "Error while reading ShaDa file: " \ entry_name " entry at position %" PRIu64 " " \ error_desc -#define CHECK_KEY(key, expected) ( \ - key.via.str.size == sizeof(expected) - 1 \ - && STRNCMP(key.via.str.ptr, expected, sizeof(expected) - 1) == 0) +#define CHECK_KEY(key, \ + expected) ((key).via.str.size == (sizeof(expected) - 1) \ + && STRNCMP((key).via.str.ptr, expected, (sizeof(expected) - 1)) == 0) #define CLEAR_GA_AND_ERROR_OUT(ga) \ do { \ - ga_clear(&ga); \ + ga_clear(&(ga)); \ goto shada_read_next_item_error; \ } while (0) #define ID(s) s -#define BINDUP(b) xmemdupz(b.ptr, b.size) +#define BINDUP(b) xmemdupz((b).ptr, (b).size) #define TOINT(s) ((int)(s)) #define TOLONG(s) ((long)(s)) #define TOCHAR(s) ((char)(s)) @@ -3334,28 +3334,31 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const semsg(_(READERR(entry_name, error_desc)), initial_fpos); \ CLEAR_GA_AND_ERROR_OUT(ad_ga); \ } \ - tgt = proc(obj.via.attr); \ + (tgt) = proc((obj).via.attr); \ } while (0) #define CHECK_KEY_IS_STR(un, entry_name) \ - if (un.data.via.map.ptr[i].key.type != MSGPACK_OBJECT_STR) { \ + if ((un).data.via.map.ptr[i].key.type != MSGPACK_OBJECT_STR) { \ semsg(_(READERR(entry_name, "has key which is not a string")), \ initial_fpos); \ CLEAR_GA_AND_ERROR_OUT(ad_ga); \ - } else if (un.data.via.map.ptr[i].key.via.str.size == 0) { \ + } else if ((un).data.via.map.ptr[i].key.via.str.size == 0) { \ semsg(_(READERR(entry_name, "has empty key")), initial_fpos); \ CLEAR_GA_AND_ERROR_OUT(ad_ga); \ } -#define CHECKED_KEY(un, entry_name, name, error_desc, tgt, condition, attr, \ - proc) \ - else if (CHECK_KEY( /* NOLINT(readability/braces) */ \ - un.data.via.map.ptr[i].key, name)) { \ - CHECKED_ENTRY(condition, "has " name " key value " error_desc, \ - entry_name, un.data.via.map.ptr[i].val, \ - tgt, attr, proc); \ +#define CHECKED_KEY(un, entry_name, name, error_desc, tgt, condition, attr, proc) \ + else if (CHECK_KEY((un).data.via.map.ptr[i].key, name)) /* NOLINT(readability/braces) */ \ + { \ + CHECKED_ENTRY(condition, \ + "has " name " key value " error_desc, \ + entry_name, \ + (un).data.via.map.ptr[i].val, \ + tgt, \ + attr, \ + proc); \ } #define TYPED_KEY(un, entry_name, name, type_name, tgt, objtype, attr, proc) \ CHECKED_KEY(un, entry_name, name, "which is not " type_name, tgt, \ - un.data.via.map.ptr[i].val.type == MSGPACK_OBJECT_##objtype, \ + (un).data.via.map.ptr[i].val.type == MSGPACK_OBJECT_##objtype, \ attr, proc) #define BOOLEAN_KEY(un, entry_name, name, tgt) \ TYPED_KEY(un, entry_name, name, "a boolean", tgt, BOOLEAN, boolean, ID) @@ -3366,9 +3369,9 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const BIN_CONVERTED) #define INT_KEY(un, entry_name, name, tgt, proc) \ CHECKED_KEY(un, entry_name, name, "which is not an integer", tgt, \ - ((un.data.via.map.ptr[i].val.type \ + (((un).data.via.map.ptr[i].val.type \ == MSGPACK_OBJECT_POSITIVE_INTEGER) \ - || (un.data.via.map.ptr[i].val.type \ + || ((un).data.via.map.ptr[i].val.type \ == MSGPACK_OBJECT_NEGATIVE_INTEGER)), \ i64, proc) #define INTEGER_KEY(un, entry_name, name, tgt) \ @@ -3379,12 +3382,12 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const else { /* NOLINT(readability/braces) */ \ ga_grow(&ad_ga, 1); \ 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)); \ + * sizeof(*(un).data.via.map.ptr)), \ + (un).data.via.map.ptr + i, \ + sizeof(*(un).data.via.map.ptr)); \ ad_ga.ga_len++; \ } -#define BIN_CONVERTED(b) (xmemdupz((b.ptr), (b.size))) +#define BIN_CONVERTED(b) (xmemdupz(((b).ptr), ((b).size))) #define SET_ADDITIONAL_DATA(tgt, name) \ do { \ if (ad_ga.ga_len) { \ @@ -3407,7 +3410,7 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const tv_clear(&adtv); \ goto shada_read_next_item_error; \ } \ - tgt = adtv.vval.v_dict; \ + (tgt) = adtv.vval.v_dict; \ } \ ga_clear(&ad_ga); \ } while (0) diff --git a/src/nvim/spell.c b/src/nvim/spell.c index da04a82d38..8f84204481 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -3519,7 +3519,7 @@ static void spell_suggest_intern(suginfo_T *su, bool interactive) // Free the info put in "*su" by spell_find_suggest(). static void spell_find_cleanup(suginfo_T *su) { -#define FREE_SUG_WORD(sug) xfree(sug->st_word) +#define FREE_SUG_WORD(sug) xfree((sug)->st_word) // Free the suggestions. GA_DEEP_CLEAR(&su->su_ga, suggest_T, FREE_SUG_WORD); GA_DEEP_CLEAR(&su->su_sga, suggest_T, FREE_SUG_WORD); diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 319cdeba35..5c2721536d 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -146,7 +146,7 @@ char *vim_strnsave_unquoted(const char *const string, const size_t length) FUNC_ATTR_NONNULL_RET { #define ESCAPE_COND(p, inquote, string_end) \ - (*p == '\\' && inquote && p + 1 < string_end && (p[1] == '\\' || p[1] == '"')) + (*(p) == '\\' && (inquote) && (p) + 1 < (string_end) && ((p)[1] == '\\' || (p)[1] == '"')) size_t ret_length = 0; bool inquote = false; const char *const string_end = string + length;