refactor: missing parenthesis may cause unexpected problems (#17443)

related vim-8.2.{4402,4639}
This commit is contained in:
kylo252 2022-05-26 04:49:25 +02:00 committed by GitHub
parent f246a929e7
commit 7b952793d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 132 additions and 127 deletions

View File

@ -45,6 +45,7 @@ IncludeCategories:
Priority: 1 Priority: 1
SortPriority: 1 SortPriority: 1
CaseSensitive: false CaseSensitive: false
AlignConsecutiveMacros: AcrossEmptyLines
IndentPPDirectives: AfterHash IndentPPDirectives: AfterHash
SpaceBeforeParens: ControlStatementsExceptControlMacros SpaceBeforeParens: ControlStatementsExceptControlMacros
ForEachMacros: ForEachMacros:

View File

@ -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]; static char out_line_buf[LINE_BUFFER_SIZE], err_line_buf[LINE_BUFFER_SIZE];
#define PUSH_CHAR(i, pos, line_buf, msg) \ #define PUSH_CHAR(i, pos, line_buf, msg) \
if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) { \ if (message.data[i] == NL || (pos) == LINE_BUFFER_SIZE - 1) { \
line_buf[pos] = NUL; \ (line_buf)[pos] = NUL; \
msg(line_buf); \ msg(line_buf); \
pos = 0; \ (pos) = 0; \
continue; \ continue; \
} \ } \
line_buf[pos++] = message.data[i]; (line_buf)[(pos)++] = message.data[i];
no_wait_return++; no_wait_return++;
for (uint32_t i = 0; i < message.size; i++) { for (uint32_t i = 0; i < message.size; i++) {

View File

@ -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); \ const uvarnumber_T digit = (uvarnumber_T)(conv); \
/* avoid ubsan error for overflow */ \ /* avoid ubsan error for overflow */ \
if (un < UVARNUMBER_MAX / base \ if (un < UVARNUMBER_MAX / (base) \
|| (un == UVARNUMBER_MAX / base \ || (un == UVARNUMBER_MAX / (base) \
&& (base != 10 || digit <= UVARNUMBER_MAX % 10))) { \ && ((base) != 10 || digit <= UVARNUMBER_MAX % 10))) { \
un = base * un + digit; \ un = (base) * un + digit; \
} else { \ } else { \
un = UVARNUMBER_MAX; \ un = UVARNUMBER_MAX; \
} \ } \

View File

@ -444,7 +444,7 @@ bool dbg_check_skipped(exarg_T *eap)
static garray_T dbg_breakp = { 0, 0, sizeof(struct debuggy), 4, NULL }; static garray_T dbg_breakp = { 0, 0, sizeof(struct debuggy), 4, NULL };
#define BREAKP(idx) (((struct debuggy *)dbg_breakp.ga_data)[idx]) #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 static int last_breakp = 0; // nr of last defined breakpoint
// Profiling uses file and func names similar to breakpoints. // Profiling uses file and func names similar to breakpoints.

View File

@ -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) \ #define FREE_CPTEXT(cptext, cptext_allocated) \
do { \ do { \
if (cptext != NULL && cptext_allocated) { \ if ((cptext) != NULL && (cptext_allocated)) { \
for (size_t i = 0; i < CPT_COUNT; i++) { \ for (size_t i = 0; i < CPT_COUNT; i++) { \
xfree(cptext[i]); \ xfree((cptext)[i]); \
} \ } \
} \ } \
} while (0) } while (0)

View File

@ -124,13 +124,13 @@ typedef struct {
#define VV(idx, name, type, flags) \ #define VV(idx, name, type, flags) \
[idx] = { \ [idx] = { \
.vv_name = name, \ .vv_name = (name), \
.vv_di = { \ .vv_di = { \
.di_tv = { .v_type = type }, \ .di_tv = { .v_type = (type) }, \
.di_flags = 0, \ .di_flags = 0, \
.di_key = { 0 }, \ .di_key = { 0 }, \
}, \ }, \
.vv_flags = flags, \ .vv_flags = (flags), \
} }
#define VIMVAR_KEY_LEN 16 // Maximum length of the key of v:variables #define VIMVAR_KEY_LEN 16 // Maximum length of the key of v:variables

View File

@ -414,9 +414,9 @@ static inline int parse_json_string(const char *const buf, const size_t buf_len,
bool hasnul = false; bool hasnul = false;
#define PUT_FST_IN_PAIR(fst_in_pair, str_end) \ #define PUT_FST_IN_PAIR(fst_in_pair, str_end) \
do { \ do { \
if (fst_in_pair != 0) { \ if ((fst_in_pair) != 0) { \
str_end += utf_char2bytes(fst_in_pair, str_end); \ (str_end) += utf_char2bytes(fst_in_pair, (str_end)); \
fst_in_pair = 0; \ (fst_in_pair) = 0; \
} \ } \
} while (0) } while (0)
for (const char *t = s; t < p; t++) { for (const char *t = s; t < p; t++) {

View File

@ -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) \ #define TYPVAL_ENCODE_CONV_STRING(tv, buf, len) \
do { \ do { \
const char *const buf_ = (const char *)buf; \ const char *const buf_ = (const char *)(buf); \
if (buf == NULL) { \ if ((buf) == NULL) { \
ga_concat(gap, "''"); \ ga_concat(gap, "''"); \
} else { \ } else { \
const size_t len_ = (len); \ 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) \ #define TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS(tv, len) \
do { \ do { \
if (len != 0) { \ if ((len) != 0) { \
ga_concat(gap, ", "); \ ga_concat(gap, ", "); \
} \ } \
} while (0) } while (0)
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, len) \ #define TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, len) \
do { \ do { \
if ((ptrdiff_t)len != -1) { \ if ((ptrdiff_t)(len) != -1) { \
ga_concat(gap, ", "); \ ga_concat(gap, ", "); \
} \ } \
} while (0) } while (0)
@ -452,12 +452,12 @@ int encode_read_from_list(ListReaderState *const state, char *const buf, const s
size_t backref = 0; \ size_t backref = 0; \
for (; backref < kv_size(*mpstack); backref++) { \ for (; backref < kv_size(*mpstack); backref++) { \
const MPConvStackVal mpval = kv_A(*mpstack, backref); \ const MPConvStackVal mpval = kv_A(*mpstack, backref); \
if (mpval.type == conv_type) { \ if (mpval.type == (conv_type)) { \
if (conv_type == kMPConvDict) { \ if ((conv_type) == kMPConvDict) { \
if ((void *)mpval.data.d.dict == (void *)(val)) { \ if ((void *)mpval.data.d.dict == (void *)(val)) { \
break; \ break; \
} \ } \
} else if (conv_type == kMPConvList) { \ } else if ((conv_type) == kMPConvList) { \
if ((void *)mpval.data.l.list == (void *)(val)) { \ if ((void *)mpval.data.l.list == (void *)(val)) { \
break; \ break; \
} \ } \
@ -487,19 +487,19 @@ int encode_read_from_list(ListReaderState *const state, char *const buf, const s
size_t backref = 0; \ size_t backref = 0; \
for (; backref < kv_size(*mpstack); backref++) { \ for (; backref < kv_size(*mpstack); backref++) { \
const MPConvStackVal mpval = kv_A(*mpstack, backref); \ const MPConvStackVal mpval = kv_A(*mpstack, backref); \
if (mpval.type == conv_type) { \ if (mpval.type == (conv_type)) { \
if (conv_type == kMPConvDict) { \ if ((conv_type) == kMPConvDict) { \
if ((void *)mpval.data.d.dict == (void *)val) { \ if ((void *)mpval.data.d.dict == (void *)(val)) { \
break; \ break; \
} \ } \
} else if (conv_type == kMPConvList) { \ } else if ((conv_type) == kMPConvList) { \
if ((void *)mpval.data.l.list == (void *)val) { \ if ((void *)mpval.data.l.list == (void *)(val)) { \
break; \ break; \
} \ } \
} \ } \
} \ } \
} \ } \
if (conv_type == kMPConvDict) { \ if ((conv_type) == kMPConvDict) { \
vim_snprintf(ebuf, ARRAY_SIZE(ebuf), "{...@%zu}", backref); \ vim_snprintf(ebuf, ARRAY_SIZE(ebuf), "{...@%zu}", backref); \
} else { \ } else { \
vim_snprintf(ebuf, ARRAY_SIZE(ebuf), "[...@%zu]", backref); \ 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 // This is done to make resulting values displayable on screen also not from
// Neovim. // Neovim.
#define ENCODE_RAW(ch) \ #define ENCODE_RAW(ch) \
(ch >= 0x20 && utf_printable(ch)) ((ch) >= 0x20 && utf_printable(ch))
for (size_t i = 0; i < utf_len;) { for (size_t i = 0; i < utf_len;) {
const int ch = utf_ptr2char(utf_buf + i); const int ch = utf_ptr2char(utf_buf + i);
const size_t shift = (ch == 0 ? 1 : ((size_t)utf_ptr2len(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 #undef TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK
#define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK(label, key) \ #define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK(label, key) \
do { \ do { \
if (!encode_check_json_key(&key)) { \ if (!encode_check_json_key(&(key))) { \
emsg(_("E474: Invalid key in special dictionary")); \ emsg(_("E474: Invalid key in special dictionary")); \
goto label; \ goto label; \
} \ } \
@ -911,7 +911,7 @@ char *encode_tv2json(typval_T *tv, size_t *len)
#define TYPVAL_ENCODE_CONV_STRING(tv, buf, len) \ #define TYPVAL_ENCODE_CONV_STRING(tv, buf, len) \
do { \ do { \
if (buf == NULL) { \ if ((buf) == NULL) { \
msgpack_pack_bin(packer, 0); \ msgpack_pack_bin(packer, 0); \
} else { \ } else { \
const size_t len_ = (len); \ 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) \ #define TYPVAL_ENCODE_CONV_STR_STRING(tv, buf, len) \
do { \ do { \
if (buf == NULL) { \ if ((buf) == NULL) { \
msgpack_pack_str(packer, 0); \ msgpack_pack_str(packer, 0); \
} else { \ } else { \
const size_t len_ = (len); \ 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) \ #define TYPVAL_ENCODE_CONV_EXT_STRING(tv, buf, len, type) \
do { \ do { \
if (buf == NULL) { \ if ((buf) == NULL) { \
msgpack_pack_ext(packer, 0, (int8_t)type); \ msgpack_pack_ext(packer, 0, (int8_t)(type)); \
} else { \ } else { \
const size_t len_ = (len); \ 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_); \ msgpack_pack_ext_body(packer, buf, len_); \
} \ } \
} while (0) } while (0)

View File

@ -879,9 +879,9 @@ void tv_list_reverse(list_T *const l)
list_log(l, NULL, NULL, "reverse"); list_log(l, NULL, NULL, "reverse");
#define SWAP(a, b) \ #define SWAP(a, b) \
do { \ do { \
tmp = a; \ tmp = (a); \
a = b; \ (a) = (b); \
b = tmp; \ (b) = tmp; \
} while (0) } while (0)
listitem_T *tmp; 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) \ #define TYPVAL_ENCODE_CONV_NIL(tv) \
do { \ do { \
tv->vval.v_special = kSpecialVarNull; \ (tv)->vval.v_special = kSpecialVarNull; \
tv->v_lock = VAR_UNLOCKED; \ (tv)->v_lock = VAR_UNLOCKED; \
} while (0) } while (0)
#define TYPVAL_ENCODE_CONV_BOOL(tv, num) \ #define TYPVAL_ENCODE_CONV_BOOL(tv, num) \
do { \ do { \
tv->vval.v_bool = kBoolVarFalse; \ (tv)->vval.v_bool = kBoolVarFalse; \
tv->v_lock = VAR_UNLOCKED; \ (tv)->v_lock = VAR_UNLOCKED; \
} while (0) } while (0)
#define TYPVAL_ENCODE_CONV_NUMBER(tv, num) \ #define TYPVAL_ENCODE_CONV_NUMBER(tv, num) \
do { \ do { \
(void)num; \ (void)(num); \
tv->vval.v_number = 0; \ (tv)->vval.v_number = 0; \
tv->v_lock = VAR_UNLOCKED; \ (tv)->v_lock = VAR_UNLOCKED; \
} while (0) } while (0)
#define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER(tv, num) #define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER(tv, num)
#define TYPVAL_ENCODE_CONV_FLOAT(tv, flt) \ #define TYPVAL_ENCODE_CONV_FLOAT(tv, flt) \
do { \ do { \
tv->vval.v_float = 0; \ (tv)->vval.v_float = 0; \
tv->v_lock = VAR_UNLOCKED; \ (tv)->v_lock = VAR_UNLOCKED; \
} while (0) } while (0)
#define TYPVAL_ENCODE_CONV_STRING(tv, buf, len) \ #define TYPVAL_ENCODE_CONV_STRING(tv, buf, len) \
do { \ do { \
xfree(buf); \ xfree(buf); \
tv->vval.v_string = NULL; \ (tv)->vval.v_string = NULL; \
tv->v_lock = VAR_UNLOCKED; \ (tv)->v_lock = VAR_UNLOCKED; \
} while (0) } while (0)
#define TYPVAL_ENCODE_CONV_STR_STRING(tv, buf, len) #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) \ #define TYPVAL_ENCODE_CONV_BLOB(tv, blob, len) \
do { \ do { \
tv_blob_unref(tv->vval.v_blob); \ tv_blob_unref((tv)->vval.v_blob); \
tv->vval.v_blob = NULL; \ (tv)->vval.v_blob = NULL; \
tv->v_lock = VAR_UNLOCKED; \ (tv)->v_lock = VAR_UNLOCKED; \
} while (0) } while (0)
static inline int _nothing_conv_func_start(typval_T *const tv, char_u *const fun) 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) \ #define TYPVAL_ENCODE_CONV_EMPTY_LIST(tv) \
do { \ do { \
tv_list_unref(tv->vval.v_list); \ tv_list_unref((tv)->vval.v_list); \
tv->vval.v_list = NULL; \ (tv)->vval.v_list = NULL; \
tv->v_lock = VAR_UNLOCKED; \ (tv)->v_lock = VAR_UNLOCKED; \
} while (0) } while (0)
static inline void _nothing_conv_empty_dict(typval_T *const tv, dict_T **const dictp) 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) \ #define TYPVAL_ENCODE_CONV_EMPTY_DICT(tv, dict) \
do { \ do { \
assert((void *)&dict != (void *)&TYPVAL_ENCODE_NODICT_VAR); \ assert((void *)&(dict) != (void *)&TYPVAL_ENCODE_NODICT_VAR); \
_nothing_conv_empty_dict(tv, ((dict_T **)&dict)); \ _nothing_conv_empty_dict(tv, ((dict_T **)&(dict))); \
} while (0) } while (0)
static inline int _nothing_conv_real_list_after_start(typval_T *const tv, 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) \ #define TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START(tv, mpsv) \
do { \ 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; \ goto typval_encode_stop_converting_one_item; \
} \ } \
} while (0) } 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) \ #define TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START(tv, dict, mpsv) \
do { \ do { \
if (_nothing_conv_real_dict_after_start(tv, (dict_T **)&dict, (void *)&TYPVAL_ENCODE_NODICT_VAR, \ if (_nothing_conv_real_dict_after_start(tv, (dict_T **)&(dict), \
&mpsv) != NOTDONE) { \ (void *)&TYPVAL_ENCODE_NODICT_VAR, &(mpsv)) \
!= NOTDONE) { \
goto typval_encode_stop_converting_one_item; \ goto typval_encode_stop_converting_one_item; \
} \ } \
} while (0) } 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) \ #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) (void *)&TYPVAL_ENCODE_NODICT_VAR)
#define TYPVAL_ENCODE_CONV_RECURSE(val, conv_type) #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 // lock/unlock the item itself
#define CHANGE_LOCK(lock, var) \ #define CHANGE_LOCK(lock, var) \
do { \ do { \
var = ((VarLockStatus[]) { \ (var) = ((VarLockStatus[]) { \
[VAR_UNLOCKED] = (lock ? VAR_LOCKED : VAR_UNLOCKED), \ [VAR_UNLOCKED] = ((lock) ? VAR_LOCKED : VAR_UNLOCKED), \
[VAR_LOCKED] = (lock ? VAR_LOCKED : VAR_UNLOCKED), \ [VAR_LOCKED] = ((lock) ? VAR_LOCKED : VAR_UNLOCKED), \
[VAR_FIXED] = VAR_FIXED, \ [VAR_FIXED] = VAR_FIXED, \
})[var]; \ })[var]; \
} while (0) } while (0)

View File

@ -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. /// Clear an argument list: free all file names and reset it to zero entries.
void alist_clear(alist_T *al) 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); GA_DEEP_CLEAR(&al->al_ga, aentry_T, FREE_AENTRY_FNAME);
} }

View File

@ -2195,11 +2195,11 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en
linenr_T lnum; linenr_T lnum;
long nchars; long nchars;
#define SET_ERRMSG_NUM(num, msg) \ #define SET_ERRMSG_NUM(num, msg) \
errnum = num, errmsg = msg, errmsgarg = 0 errnum = (num), errmsg = (msg), errmsgarg = 0
#define SET_ERRMSG_ARG(msg, error) \ #define SET_ERRMSG_ARG(msg, error) \
errnum = NULL, errmsg = msg, errmsgarg = error errnum = NULL, errmsg = (msg), errmsgarg = error
#define SET_ERRMSG(msg) \ #define SET_ERRMSG(msg) \
errnum = NULL, errmsg = msg, errmsgarg = 0 errnum = NULL, errmsg = (msg), errmsgarg = 0
const char *errnum = NULL; const char *errnum = NULL;
char *errmsg = NULL; char *errmsg = NULL;
int errmsgarg = 0; int errmsgarg = 0;

View File

@ -3799,7 +3799,7 @@ bool map_to_exists(const char *const str, const char *const modechars, const boo
#define MAPMODE(mode, modechars, chr, modeflags) \ #define MAPMODE(mode, modechars, chr, modeflags) \
do { \ do { \
if (strchr(modechars, chr) != NULL) { \ if (strchr(modechars, chr) != NULL) { \
mode |= modeflags; \ (mode) |= (modeflags); \
} \ } \
} while (0) } while (0)
MAPMODE(mode, modechars, 'n', MODE_NORMAL); MAPMODE(mode, modechars, 'n', MODE_NORMAL);

View File

@ -33,11 +33,11 @@
#define handle_T_eq kh_int_hash_equal #define handle_T_eq kh_int_hash_equal
#if defined(ARCH_64) #if defined(ARCH_64)
# define ptr_t_hash(key) uint64_t_hash((uint64_t)key) # 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_eq(a, b) uint64_t_eq((uint64_t)(a), (uint64_t)(b))
#elif defined(ARCH_32) #elif defined(ARCH_32)
# define ptr_t_hash(key) uint32_t_hash((uint32_t)key) # 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_eq(a, b) uint32_t_eq((uint32_t)(a), (uint32_t)(b))
#endif #endif
#define INITIALIZER(T, U) T##_##U##_initializer #define INITIALIZER(T, U) T##_##U##_initializer

View File

@ -58,7 +58,7 @@
#define ID_INCR (((uint64_t)1) << 2) #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) static bool pos_leq(mtpos_t a, mtpos_t b)
{ {

View File

@ -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) \ #define ADD_STATE_IF_MATCH(state) \
if (result) { \ if (result) { \
add_state = state->out; \ add_state = (state)->out; \
add_off = clen; \ add_off = clen; \
} }

View File

@ -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}`). /// @return `for` cycle header (use `HMLL_FORALL(hmll, cur_entry) {body}`).
#define HMLL_FORALL(hmll, cur_entry, code) \ #define HMLL_FORALL(hmll, cur_entry, code) \
for (HMLListEntry *cur_entry = (hmll)->first; cur_entry != NULL; \ for (HMLListEntry *(cur_entry) = (hmll)->first; (cur_entry) != NULL; \
cur_entry = cur_entry->next) { \ (cur_entry) = (cur_entry)->next) { \
code \ 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, \ entry, fname_cond, free_func, fin_func, \
idxadj_func, afterfree_func) \ idxadj_func, afterfree_func) \
do { \ do { \
const int jl_len = (int)jumps_size; \ const int jl_len = (int)(jumps_size); \
int i; \ int i; \
for (i = jl_len; i > 0; i--) { \ for (i = jl_len; i > 0; i--) { \
const jumps_type jl_entry = jumps[i - 1]; \ const jumps_type jl_entry = (jumps)[i - 1]; \
if (jl_entry.timestamp_attr <= entry.timestamp) { \ if (jl_entry.timestamp_attr <= (entry).timestamp) { \
if (marks_equal(jl_entry.mark_attr, entry.data.filemark.mark) \ if (marks_equal(jl_entry.mark_attr, (entry).data.filemark.mark) \
&& fname_cond) { \ && (fname_cond)) { \
i = -1; \ i = -1; \
} \ } \
break; \ break; \
@ -1086,30 +1086,30 @@ static inline bool marks_equal(const pos_T a, const pos_T b)
} \ } \
if (i > 0) { \ if (i > 0) { \
if (jl_len == JUMPLISTSIZE) { \ if (jl_len == JUMPLISTSIZE) { \
free_func(jumps[0]); \ free_func((jumps)[0]); \
i--; \ i--; \
if (i > 0) { \ 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) { \ } else if (i != jl_len) { \
memmove(&jumps[i + 1], &jumps[i], \ memmove(&(jumps)[i + 1], &(jumps)[i], \
sizeof(jumps[0]) * (size_t)(jl_len - i)); \ sizeof((jumps)[0]) * (size_t)(jl_len - i)); \
} \ } \
} else if (i == 0) { \ } else if (i == 0) { \
if (jl_len == JUMPLISTSIZE) { \ if (jl_len == JUMPLISTSIZE) { \
i = -1; \ i = -1; \
} else if (jl_len > 0) { \ } 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) { \ if (i != -1) { \
jumps[i] = fin_func(entry); \ (jumps)[i] = fin_func(entry); \
if (jl_len < JUMPLISTSIZE) { \ if (jl_len < JUMPLISTSIZE) { \
jumps_size++; \ (jumps_size)++; \
} \ } \
idxadj_func(i); \ idxadj_func(i); \
} else { \ } else { \
shada_free_shada_entry(&entry); \ shada_free_shada_entry(&(entry)); \
afterfree_func(entry); \ afterfree_func(entry); \
} \ } \
} while (0) } while (0)
@ -1304,7 +1304,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags)
} else { } else {
#define SDE_TO_XFMARK(entry) fm #define SDE_TO_XFMARK(entry) fm
#define ADJUST_IDX(i) \ #define ADJUST_IDX(i) \
if (curwin->w_jumplistidx >= i \ if (curwin->w_jumplistidx >= (i) \
&& curwin->w_jumplistidx + 1 <= curwin->w_jumplistlen) { \ && curwin->w_jumplistidx + 1 <= curwin->w_jumplistlen) { \
curwin->w_jumplistidx++; \ curwin->w_jumplistidx++; \
} }
@ -1547,7 +1547,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr
} \ } \
} while (0) } while (0)
#define CHECK_DEFAULT(entry, attr) \ #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) \ #define ONE_IF_NOT_DEFAULT(entry, attr) \
((size_t)(!CHECK_DEFAULT(entry, attr))) ((size_t)(!CHECK_DEFAULT(entry, attr)))
switch (entry.type) { switch (entry.type) {
@ -1637,7 +1637,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr
do { \ do { \
if (!CHECK_DEFAULT(entry, search_pattern.attr)) { \ if (!CHECK_DEFAULT(entry, search_pattern.attr)) { \
PACK_STATIC_STR(name); \ 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); \ msgpack_pack_false(spacker); \
} else { \ } else { \
msgpack_pack_true(spacker); \ msgpack_pack_true(spacker); \
@ -2221,12 +2221,12 @@ static inline ShaDaWriteResult shada_read_when_writing(ShaDaReadDef *const sd_re
} else { } else {
#define FREE_POSSIBLY_FREED_SHADA_ENTRY(entry) \ #define FREE_POSSIBLY_FREED_SHADA_ENTRY(entry) \
do { \ do { \
if (entry.can_free_entry) { \ if ((entry).can_free_entry) { \
shada_free_shada_entry(&entry.data); \ shada_free_shada_entry(&(entry).data); \
} \ } \
} while (0) } while (0)
#define SDE_TO_PFSDE(entry) \ #define SDE_TO_PFSDE(entry) \
((PossiblyFreedShadaEntry) { .can_free_entry = true, .data = entry }) ((PossiblyFreedShadaEntry) { .can_free_entry = true, .data = (entry) })
#define AFTERFREE_DUMMY(entry) #define AFTERFREE_DUMMY(entry)
#define DUMMY_IDX_ADJ(i) #define DUMMY_IDX_ADJ(i)
MERGE_JUMPS(filemarks->changes_size, filemarks->changes, 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) \ #define PACK_WMS_ARRAY(wms_array) \
do { \ do { \
for (size_t i_ = 0; i_ < ARRAY_SIZE(wms_array); i_++) { \ for (size_t i_ = 0; i_ < ARRAY_SIZE(wms_array); i_++) { \
if (wms_array[i_].data.type != kSDItemMissing) { \ if ((wms_array)[i_].data.type != kSDItemMissing) { \
if (shada_pack_pfreed_entry(packer, wms_array[i_], max_kbyte) \ if (shada_pack_pfreed_entry(packer, (wms_array)[i_], max_kbyte) \
== kSDWriteFailed) { \ == kSDWriteFailed) { \
ret = kSDWriteFailed; \ ret = kSDWriteFailed; \
goto shada_write_exit; \ goto shada_write_exit; \
@ -2835,7 +2835,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef
} }
#define PACK_WMS_ENTRY(wms_entry) \ #define PACK_WMS_ENTRY(wms_entry) \
do { \ do { \
if (wms_entry.data.type != kSDItemMissing) { \ if ((wms_entry).data.type != kSDItemMissing) { \
if (shada_pack_pfreed_entry(packer, wms_entry, max_kbyte) \ if (shada_pack_pfreed_entry(packer, wms_entry, max_kbyte) \
== kSDWriteFailed) { \ == kSDWriteFailed) { \
ret = kSDWriteFailed; \ ret = kSDWriteFailed; \
@ -3312,16 +3312,16 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const
RERR "Error while reading ShaDa file: " \ RERR "Error while reading ShaDa file: " \
entry_name " entry at position %" PRIu64 " " \ entry_name " entry at position %" PRIu64 " " \
error_desc error_desc
#define CHECK_KEY(key, expected) ( \ #define CHECK_KEY(key, \
key.via.str.size == sizeof(expected) - 1 \ expected) ((key).via.str.size == (sizeof(expected) - 1) \
&& STRNCMP(key.via.str.ptr, expected, sizeof(expected) - 1) == 0) && STRNCMP((key).via.str.ptr, expected, (sizeof(expected) - 1)) == 0)
#define CLEAR_GA_AND_ERROR_OUT(ga) \ #define CLEAR_GA_AND_ERROR_OUT(ga) \
do { \ do { \
ga_clear(&ga); \ ga_clear(&(ga)); \
goto shada_read_next_item_error; \ goto shada_read_next_item_error; \
} while (0) } while (0)
#define ID(s) s #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 TOINT(s) ((int)(s))
#define TOLONG(s) ((long)(s)) #define TOLONG(s) ((long)(s))
#define TOCHAR(s) ((char)(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); \ semsg(_(READERR(entry_name, error_desc)), initial_fpos); \
CLEAR_GA_AND_ERROR_OUT(ad_ga); \ CLEAR_GA_AND_ERROR_OUT(ad_ga); \
} \ } \
tgt = proc(obj.via.attr); \ (tgt) = proc((obj).via.attr); \
} while (0) } while (0)
#define CHECK_KEY_IS_STR(un, entry_name) \ #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")), \ semsg(_(READERR(entry_name, "has key which is not a string")), \
initial_fpos); \ initial_fpos); \
CLEAR_GA_AND_ERROR_OUT(ad_ga); \ 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); \ semsg(_(READERR(entry_name, "has empty key")), initial_fpos); \
CLEAR_GA_AND_ERROR_OUT(ad_ga); \ CLEAR_GA_AND_ERROR_OUT(ad_ga); \
} }
#define CHECKED_KEY(un, entry_name, name, error_desc, tgt, condition, attr, \ #define CHECKED_KEY(un, entry_name, name, error_desc, tgt, condition, attr, proc) \
proc) \ else if (CHECK_KEY((un).data.via.map.ptr[i].key, name)) /* NOLINT(readability/braces) */ \
else if (CHECK_KEY( /* NOLINT(readability/braces) */ \ { \
un.data.via.map.ptr[i].key, name)) { \ CHECKED_ENTRY(condition, \
CHECKED_ENTRY(condition, "has " name " key value " error_desc, \ "has " name " key value " error_desc, \
entry_name, un.data.via.map.ptr[i].val, \ entry_name, \
tgt, attr, proc); \ (un).data.via.map.ptr[i].val, \
tgt, \
attr, \
proc); \
} }
#define TYPED_KEY(un, entry_name, name, type_name, tgt, objtype, 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, \ 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) attr, proc)
#define BOOLEAN_KEY(un, entry_name, name, tgt) \ #define BOOLEAN_KEY(un, entry_name, name, tgt) \
TYPED_KEY(un, entry_name, name, "a boolean", tgt, BOOLEAN, boolean, ID) 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) BIN_CONVERTED)
#define INT_KEY(un, entry_name, name, tgt, proc) \ #define INT_KEY(un, entry_name, name, tgt, proc) \
CHECKED_KEY(un, entry_name, name, "which is not an integer", tgt, \ 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) \ == MSGPACK_OBJECT_POSITIVE_INTEGER) \
|| (un.data.via.map.ptr[i].val.type \ || ((un).data.via.map.ptr[i].val.type \
== MSGPACK_OBJECT_NEGATIVE_INTEGER)), \ == MSGPACK_OBJECT_NEGATIVE_INTEGER)), \
i64, proc) i64, proc)
#define INTEGER_KEY(un, entry_name, name, tgt) \ #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) */ \ else { /* NOLINT(readability/braces) */ \
ga_grow(&ad_ga, 1); \ ga_grow(&ad_ga, 1); \
memcpy(((char *)ad_ga.ga_data) + ((size_t)ad_ga.ga_len \ memcpy(((char *)ad_ga.ga_data) + ((size_t)ad_ga.ga_len \
* sizeof(*un.data.via.map.ptr)), \ * sizeof(*(un).data.via.map.ptr)), \
un.data.via.map.ptr + i, \ (un).data.via.map.ptr + i, \
sizeof(*un.data.via.map.ptr)); \ sizeof(*(un).data.via.map.ptr)); \
ad_ga.ga_len++; \ 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) \ #define SET_ADDITIONAL_DATA(tgt, name) \
do { \ do { \
if (ad_ga.ga_len) { \ if (ad_ga.ga_len) { \
@ -3407,7 +3410,7 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const
tv_clear(&adtv); \ tv_clear(&adtv); \
goto shada_read_next_item_error; \ goto shada_read_next_item_error; \
} \ } \
tgt = adtv.vval.v_dict; \ (tgt) = adtv.vval.v_dict; \
} \ } \
ga_clear(&ad_ga); \ ga_clear(&ad_ga); \
} while (0) } while (0)

View File

@ -3519,7 +3519,7 @@ static void spell_suggest_intern(suginfo_T *su, bool interactive)
// Free the info put in "*su" by spell_find_suggest(). // Free the info put in "*su" by spell_find_suggest().
static void spell_find_cleanup(suginfo_T *su) 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. // Free the suggestions.
GA_DEEP_CLEAR(&su->su_ga, suggest_T, FREE_SUG_WORD); GA_DEEP_CLEAR(&su->su_ga, suggest_T, FREE_SUG_WORD);
GA_DEEP_CLEAR(&su->su_sga, suggest_T, FREE_SUG_WORD); GA_DEEP_CLEAR(&su->su_sga, suggest_T, FREE_SUG_WORD);

View File

@ -146,7 +146,7 @@ char *vim_strnsave_unquoted(const char *const string, const size_t length)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_RET
{ {
#define ESCAPE_COND(p, inquote, string_end) \ #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; size_t ret_length = 0;
bool inquote = false; bool inquote = false;
const char *const string_end = string + length; const char *const string_end = string + length;