aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval
diff options
context:
space:
mode:
authorkylo252 <59826753+kylo252@users.noreply.github.com>2022-05-26 04:49:25 +0200
committerGitHub <noreply@github.com>2022-05-26 10:49:25 +0800
commit7b952793d5c46e862a9cdec3d6ac4762370296ed (patch)
tree987ea7d0174b4df4a6aa19356237b08308b0e744 /src/nvim/eval
parentf246a929e7abec4aba00ceb68b1492f3be5877dc (diff)
downloadrneovim-7b952793d5c46e862a9cdec3d6ac4762370296ed.tar.gz
rneovim-7b952793d5c46e862a9cdec3d6ac4762370296ed.tar.bz2
rneovim-7b952793d5c46e862a9cdec3d6ac4762370296ed.zip
refactor: missing parenthesis may cause unexpected problems (#17443)
related vim-8.2.{4402,4639}
Diffstat (limited to 'src/nvim/eval')
-rw-r--r--src/nvim/eval/decode.c6
-rw-r--r--src/nvim/eval/encode.c40
-rw-r--r--src/nvim/eval/typval.c59
3 files changed, 53 insertions, 52 deletions
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)