From f551df17f33e7f38b7e5693eb923118ca1542d27 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 10 Jul 2016 08:03:14 +0300 Subject: viml/executor: Directly generate typval_T values Note: this will *still* crash when using API in cases similar to the one described in first commit. Just it needs different code to reproduce. --- src/nvim/eval/decode.c | 138 +++++++++++++++++++++++++++---------------------- 1 file changed, 76 insertions(+), 62 deletions(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/decode.c b/src/nvim/eval/decode.c index 43e9f76c0f..cb5a624f7b 100644 --- a/src/nvim/eval/decode.c +++ b/src/nvim/eval/decode.c @@ -7,6 +7,7 @@ #include "nvim/eval/encode.h" #include "nvim/ascii.h" #include "nvim/message.h" +#include "nvim/globals.h" #include "nvim/charset.h" // vim_str2nr #include "nvim/lib/kvec.h" #include "nvim/vim.h" // OK, FAIL @@ -218,6 +219,69 @@ static inline int json_decoder_pop(ValuesStackItem obj, } \ } while (0) +/// Create a new special dictionary that ought to represent a MAP +/// +/// @param[out] ret_tv Address where new special dictionary is saved. +/// +/// @return [allocated] list which should contain key-value pairs. Return value +/// may be safely ignored. +list_T *decode_create_map_special_dict(typval_T *const ret_tv) + FUNC_ATTR_NONNULL_ALL +{ + list_T *const list = list_alloc(); + list->lv_refcount++; + create_special_dict(ret_tv, kMPMap, ((typval_T) { + .v_type = VAR_LIST, + .v_lock = VAR_UNLOCKED, + .vval = { .v_list = list }, + })); + return list; +} + +/// Convert char* string to typval_T +/// +/// Depending on whether string has (no) NUL bytes, it may use a special +/// dictionary or decode string to VAR_STRING. +/// +/// @param[in] s String to decode. +/// @param[in] len String length. +/// @param[in] hasnul Whether string has NUL byte, not or it was not yet +/// determined. +/// @param[in] binary If true, save special string type as kMPBinary, +/// otherwise kMPString. +/// +/// @return Decoded string. +typval_T decode_string(const char *const s, const size_t len, + const TriState hasnul, const bool binary) + FUNC_ATTR_WARN_UNUSED_RESULT +{ + assert(s != NULL || len == 0); + const bool really_hasnul = (hasnul == kNone + ? memchr(s, NUL, len) != NULL + : (bool)hasnul); + if (really_hasnul) { + list_T *const list = list_alloc(); + list->lv_refcount++; + typval_T tv; + create_special_dict(&tv, binary ? kMPBinary : kMPString, ((typval_T) { + .v_type = VAR_LIST, + .v_lock = VAR_UNLOCKED, + .vval = { .v_list = list }, + })); + if (encode_list_write((void *)list, s, len) == -1) { + clear_tv(&tv); + return (typval_T) { .v_type = VAR_UNKNOWN, .v_lock = VAR_UNLOCKED }; + } + return tv; + } else { + return (typval_T) { + .v_type = VAR_STRING, + .v_lock = VAR_UNLOCKED, + .vval = { .v_string = xmemdupz(s, len) }, + }; + } +} + /// Parse JSON double-quoted string /// /// @param[in] conv Defines conversion necessary to convert UTF-8 string to @@ -428,29 +492,13 @@ static inline int parse_json_string(vimconv_T *const conv, str = new_str; str_end = new_str + str_len; } - if (hasnul) { - typval_T obj; - list_T *const list = list_alloc(); - list->lv_refcount++; - create_special_dict(&obj, kMPString, ((typval_T) { - .v_type = VAR_LIST, - .v_lock = VAR_UNLOCKED, - .vval = { .v_list = list }, - })); - if (encode_list_write((void *) list, str, (size_t) (str_end - str)) - == -1) { - clear_tv(&obj); - goto parse_json_string_fail; - } - xfree(str); - POP(obj, true); - } else { - *str_end = NUL; - POP(((typval_T) { - .v_type = VAR_STRING, - .vval = { .v_string = (char_u *) str }, - }), false); + typval_T obj; + obj = decode_string(str, (size_t)(str_end - str), hasnul ? kTrue : kFalse, + false); + if (obj.v_type == VAR_UNKNOWN) { + goto parse_json_string_fail; } + POP(obj, obj.v_type != VAR_STRING); goto parse_json_string_ret; parse_json_string_fail: ret = FAIL; @@ -827,13 +875,7 @@ json_decode_string_cycle_start: list_T *val_list = NULL; if (next_map_special) { next_map_special = false; - val_list = list_alloc(); - val_list->lv_refcount++; - create_special_dict(&tv, kMPMap, ((typval_T) { - .v_type = VAR_LIST, - .v_lock = VAR_UNLOCKED, - .vval = { .v_list = val_list }, - })); + val_list = decode_create_map_special_dict(&tv); } else { dict_T *dict = dict_alloc(); dict->dv_refcount++; @@ -980,37 +1022,15 @@ int msgpack_to_vim(const msgpack_object mobj, typval_T *const rettv) break; } case MSGPACK_OBJECT_STR: { - list_T *const list = list_alloc(); - list->lv_refcount++; - create_special_dict(rettv, kMPString, ((typval_T) { - .v_type = VAR_LIST, - .v_lock = VAR_UNLOCKED, - .vval = { .v_list = list }, - })); - if (encode_list_write((void *) list, mobj.via.str.ptr, mobj.via.str.size) - == -1) { + *rettv = decode_string(mobj.via.bin.ptr, mobj.via.bin.size, kTrue, false); + if (rettv->v_type == VAR_UNKNOWN) { return FAIL; } break; } case MSGPACK_OBJECT_BIN: { - if (memchr(mobj.via.bin.ptr, NUL, mobj.via.bin.size) == NULL) { - *rettv = (typval_T) { - .v_type = VAR_STRING, - .v_lock = VAR_UNLOCKED, - .vval = { .v_string = xmemdupz(mobj.via.bin.ptr, mobj.via.bin.size) }, - }; - break; - } - list_T *const list = list_alloc(); - list->lv_refcount++; - create_special_dict(rettv, kMPBinary, ((typval_T) { - .v_type = VAR_LIST, - .v_lock = VAR_UNLOCKED, - .vval = { .v_list = list }, - })); - if (encode_list_write((void *) list, mobj.via.bin.ptr, mobj.via.bin.size) - == -1) { + *rettv = decode_string(mobj.via.bin.ptr, mobj.via.bin.size, kNone, true); + if (rettv->v_type == VAR_UNKNOWN) { return FAIL; } break; @@ -1067,13 +1087,7 @@ int msgpack_to_vim(const msgpack_object mobj, typval_T *const rettv) } break; msgpack_to_vim_generic_map: {} - list_T *const list = list_alloc(); - list->lv_refcount++; - create_special_dict(rettv, kMPMap, ((typval_T) { - .v_type = VAR_LIST, - .v_lock = VAR_UNLOCKED, - .vval = { .v_list = list }, - })); + list_T *const list = decode_create_map_special_dict(rettv); for (size_t i = 0; i < mobj.via.map.size; i++) { list_T *const kv_pair = list_alloc(); list_append_list(list, kv_pair); -- cgit From 45feaa73d0759858a9a4454037fe4a41ea97e5b9 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 21 Jan 2017 00:16:25 +0300 Subject: eval/decode: Fix memory leak in JSON functions --- src/nvim/eval/decode.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/decode.c b/src/nvim/eval/decode.c index cb5a624f7b..d95e75170a 100644 --- a/src/nvim/eval/decode.c +++ b/src/nvim/eval/decode.c @@ -249,10 +249,14 @@ list_T *decode_create_map_special_dict(typval_T *const ret_tv) /// determined. /// @param[in] binary If true, save special string type as kMPBinary, /// otherwise kMPString. +/// @param[in] s_allocated If true, then `s` was allocated and can be saved in +/// a returned structure. If it is not saved there, it +/// will be freed. /// /// @return Decoded string. typval_T decode_string(const char *const s, const size_t len, - const TriState hasnul, const bool binary) + const TriState hasnul, const bool binary, + const bool s_allocated) FUNC_ATTR_WARN_UNUSED_RESULT { assert(s != NULL || len == 0); @@ -268,7 +272,11 @@ typval_T decode_string(const char *const s, const size_t len, .v_lock = VAR_UNLOCKED, .vval = { .v_list = list }, })); - if (encode_list_write((void *)list, s, len) == -1) { + const int elw_ret = encode_list_write((void *)list, s, len); + if (s_allocated) { + xfree((void *)s); + } + if (elw_ret == -1) { clear_tv(&tv); return (typval_T) { .v_type = VAR_UNKNOWN, .v_lock = VAR_UNLOCKED }; } @@ -277,7 +285,8 @@ typval_T decode_string(const char *const s, const size_t len, return (typval_T) { .v_type = VAR_STRING, .v_lock = VAR_UNLOCKED, - .vval = { .v_string = xmemdupz(s, len) }, + .vval = { .v_string = (char_u *)( + s_allocated ? (char *)s : xmemdupz(s, len)) }, }; } } @@ -492,9 +501,10 @@ static inline int parse_json_string(vimconv_T *const conv, str = new_str; str_end = new_str + str_len; } + *str_end = NUL; typval_T obj; obj = decode_string(str, (size_t)(str_end - str), hasnul ? kTrue : kFalse, - false); + false, true); if (obj.v_type == VAR_UNKNOWN) { goto parse_json_string_fail; } @@ -1022,14 +1032,16 @@ int msgpack_to_vim(const msgpack_object mobj, typval_T *const rettv) break; } case MSGPACK_OBJECT_STR: { - *rettv = decode_string(mobj.via.bin.ptr, mobj.via.bin.size, kTrue, false); + *rettv = decode_string(mobj.via.bin.ptr, mobj.via.bin.size, kTrue, false, + false); if (rettv->v_type == VAR_UNKNOWN) { return FAIL; } break; } case MSGPACK_OBJECT_BIN: { - *rettv = decode_string(mobj.via.bin.ptr, mobj.via.bin.size, kNone, true); + *rettv = decode_string(mobj.via.bin.ptr, mobj.via.bin.size, kNone, true, + false); if (rettv->v_type == VAR_UNKNOWN) { return FAIL; } -- cgit From 927e6efc3d93ff9d34c532180591dc3ca326edf5 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 22 Jan 2017 05:16:05 +0300 Subject: clint: Allow omitting include guards in .c.h file and func_attr.h file --- src/nvim/eval/typval_encode.c.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/typval_encode.c.h b/src/nvim/eval/typval_encode.c.h index 4ff5589887..812340b9c3 100644 --- a/src/nvim/eval/typval_encode.c.h +++ b/src/nvim/eval/typval_encode.c.h @@ -233,10 +233,6 @@ /// /// This name will only be used by one of the above macros which are defined by /// the caller. Functions defined here do not use first argument directly. -#ifndef NVIM_EVAL_TYPVAL_ENCODE_C_H -#define NVIM_EVAL_TYPVAL_ENCODE_C_H -#undef NVIM_EVAL_TYPVAL_ENCODE_C_H - #include #include #include @@ -816,4 +812,3 @@ encode_vim_to__error_ret: // Prevent “unused label” warnings. goto typval_encode_stop_converting_one_item; } -#endif // NVIM_EVAL_TYPVAL_ENCODE_C_H -- cgit From 57308c4f82aa18b4c6a1af76d224c40e442c9a1e Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 10 Apr 2017 23:22:59 +0300 Subject: eval/decode: Include header needed for TriState --- src/nvim/eval/decode.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/decode.h b/src/nvim/eval/decode.h index c8e7a189e3..77fc4c78c2 100644 --- a/src/nvim/eval/decode.h +++ b/src/nvim/eval/decode.h @@ -6,6 +6,7 @@ #include #include "nvim/eval/typval.h" +#include "nvim/globals.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "eval/decode.h.generated.h" -- cgit From f4d5d5250a105b5593e3119f4ee37ea20272a34b Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 1 Apr 2017 23:57:34 +0300 Subject: eval: Refactor get_user_input to support dictionary --- src/nvim/eval/typval.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 786b766689..e721ebe345 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1225,6 +1225,31 @@ const char *tv_dict_get_string_buf(const dict_T *const d, const char *const key, return tv_get_string_buf(&di->di_tv, numbuf); } +/// Get a string item from a dictionary +/// +/// @param[in] d Dictionary to get item from. +/// @param[in] key Dictionary key. +/// @param[in] key_len Key length. +/// @param[in] numbuf Numbuf for. +/// @param[in] def Default return when key does not exist. +/// +/// @return `def` when key does not exist, +/// NULL in case of type error, +/// string item value in case of success. +const char *tv_dict_get_string_buf_chk(const dict_T *const d, + const char *const key, + const ptrdiff_t key_len, + char *const numbuf, + const char *const def) + FUNC_ATTR_WARN_UNUSED_RESULT +{ + const dictitem_T *const di = tv_dict_find(d, key, key_len); + if (di == NULL) { + return def; + } + return tv_get_string_buf_chk(&di->di_tv, numbuf); +} + /// Get a function from a dictionary /// /// @param[in] d Dictionary to get callback from. -- cgit From 5ec72aadbf51a729969cb7f9f06cf573fc77da59 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 3 May 2017 00:08:10 -0400 Subject: *: Use __attribute__((fallthrough)) where comments aren't supported Although GCC now detects possibly unintentional fall through, there rules around which the comments are detected are rather strict. In cases where a comment isn't detected, upstream [recommends] using their fallthrough attribute. [recommends]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77817#c11 --- src/nvim/eval/typval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 786b766689..19d9d56058 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1869,7 +1869,7 @@ void tv_free(typval_T *tv) } case VAR_FUNC: { func_unref(tv->vval.v_string); - // FALLTHROUGH + FALLTHROUGH; } case VAR_STRING: { xfree(tv->vval.v_string); -- cgit From d66ef56739f9b666e54173d7642c0b351f0c2c12 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 13 May 2017 17:01:22 +0300 Subject: eval/typval: Fix numbuf parameter documentation --- src/nvim/eval/typval.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index e721ebe345..dd3fe22694 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1210,7 +1210,8 @@ char *tv_dict_get_string(const dict_T *const d, const char *const key, /// /// @param[in] d Dictionary to get item from. /// @param[in] key Dictionary key. -/// @param[in] numbuf Numbuf for. +/// @param[in] numbuf Buffer for non-string items converted to strings, at +/// least of #NUMBUFLEN length. /// /// @return NULL if key does not exist, empty string in case of type error, /// string item value otherwise. @@ -1230,7 +1231,8 @@ const char *tv_dict_get_string_buf(const dict_T *const d, const char *const key, /// @param[in] d Dictionary to get item from. /// @param[in] key Dictionary key. /// @param[in] key_len Key length. -/// @param[in] numbuf Numbuf for. +/// @param[in] numbuf Buffer for non-string items converted to strings, at +/// least of #NUMBUFLEN length. /// @param[in] def Default return when key does not exist. /// /// @return `def` when key does not exist, -- cgit From 1db29cb5e57da4db212b23a0a7e4e887d40315e3 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 03:47:01 +0300 Subject: eval/encode: Silence V595 error --- src/nvim/eval/encode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index 742497c1ca..ef647b3ee4 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -253,9 +253,11 @@ int encode_read_from_list(ListReaderState *const state, char *const buf, char *const buf_end = buf + nbuf; char *p = buf; while (p < buf_end) { + assert(state->li_length == 0 || state->li->li_tv.vval.v_string != NULL); for (size_t i = state->offset; i < state->li_length && p < buf_end; i++) { - const char ch = (char) state->li->li_tv.vval.v_string[state->offset++]; - *p++ = (char) ((char) ch == (char) NL ? (char) NUL : (char) ch); + assert(state->li->li_tv.vval.v_string != NULL); + const char ch = (char)state->li->li_tv.vval.v_string[state->offset++]; + *p++ = (char)((char)ch == (char)NL ? (char)NUL : (char)ch); } if (p < buf_end) { state->li = state->li->li_next; -- cgit From 81be7358be00d3d75453659bcdc7efc69207ca8e Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 16 Nov 2016 11:09:04 -0500 Subject: vim-patch:7.4.1976 Problem: Number variables are not 64 bits while they could be. Solution: Add the num64 feature. (Ken Takata) https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12 --- src/nvim/eval/decode.c | 6 +++--- src/nvim/eval/typval.h | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/decode.c b/src/nvim/eval/decode.c index 935c98fb84..bf0abe04a3 100644 --- a/src/nvim/eval/decode.c +++ b/src/nvim/eval/decode.c @@ -435,7 +435,7 @@ static inline int parse_json_string(const char *const buf, const size_t buf_len, case 'u': { const char ubuf[] = { t[1], t[2], t[3], t[4] }; t += 4; - unsigned long ch; + uvarnumber_T ch; vim_str2nr((char_u *) ubuf, NULL, NULL, STR2NR_HEX | STR2NR_FORCE, NULL, &ch, 4); if (ch == 0) { @@ -609,7 +609,7 @@ parse_json_number_check: tv.v_type = VAR_FLOAT; } else { // Convert integer - long nr; + varnumber_T nr; int num_len; vim_str2nr((char_u *) s, NULL, &num_len, 0, &nr, NULL, (int) (p - s)); if ((int) exp_num_len != num_len) { @@ -617,7 +617,7 @@ parse_json_number_check: "to integer vim_str2nr consumed %i bytes in place of %zu"), (int) exp_num_len, s, num_len, exp_num_len); } - tv.vval.v_number = (varnumber_T) nr; + tv.vval.v_number = nr; } if (json_decoder_pop(OBJ(tv, false, *didcomma, *didcolon), stack, container_stack, diff --git a/src/nvim/eval/typval.h b/src/nvim/eval/typval.h index 0f659727ee..3f8ed3b3f9 100644 --- a/src/nvim/eval/typval.h +++ b/src/nvim/eval/typval.h @@ -1,7 +1,7 @@ #ifndef NVIM_EVAL_TYPVAL_H #define NVIM_EVAL_TYPVAL_H -#include +#include #include #include #include @@ -20,20 +20,21 @@ #include "nvim/macros.h" /// Type used for VimL VAR_NUMBER values -typedef int varnumber_T; +typedef int64_t varnumber_T; +typedef uint64_t uvarnumber_T; /// Type used for VimL VAR_FLOAT values typedef double float_T; /// Maximal possible value of varnumber_T variable -#define VARNUMBER_MAX INT_MAX +#define VARNUMBER_MAX INT64_MAX +#define UVARNUMBER_MAX UINT64_MAX /// Mimimal possible value of varnumber_T variable -#define VARNUMBER_MIN INT_MIN -#define PRIdVARNUMBER "d" +#define VARNUMBER_MIN INT64_MIN /// %d printf format specifier for varnumber_T -#define PRIdVARNUMBER "d" +#define PRIdVARNUMBER PRId64 typedef struct listvar_S list_T; typedef struct dictvar_S dict_T; -- cgit From 43534cab025fa57109c832f13fb567da2299e707 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 23 Jan 2017 23:13:25 -0500 Subject: lint --- src/nvim/eval/decode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/decode.c b/src/nvim/eval/decode.c index bf0abe04a3..9c9c2c2dc8 100644 --- a/src/nvim/eval/decode.c +++ b/src/nvim/eval/decode.c @@ -436,7 +436,7 @@ static inline int parse_json_string(const char *const buf, const size_t buf_len, const char ubuf[] = { t[1], t[2], t[3], t[4] }; t += 4; uvarnumber_T ch; - vim_str2nr((char_u *) ubuf, NULL, NULL, + vim_str2nr((char_u *)ubuf, NULL, NULL, STR2NR_HEX | STR2NR_FORCE, NULL, &ch, 4); if (ch == 0) { hasnul = true; -- cgit From eb5e4a247666c0ba26b21e214249789ea7c52e85 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sat, 6 May 2017 22:35:50 -0400 Subject: *: Disable UBSAN for VimL arithmetic implementation After merging +num64, the 64-bit sanitizer builds show that Vim doesn't buffer the user from C's UB in signed arithmetic. Upstream doesn't appear to be [interested] in fixing the issue, so suppress UBSAN until someone decides to fix the problem. N.B., the problem existed before but went unnoticed since the sanitizer builds weren't being run in 32-bit mode. [interested]: https://groups.google.com/d/topic/vim_dev/_tqf8eQy5eA/discussion --- src/nvim/eval/executor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/executor.c b/src/nvim/eval/executor.c index 91bb61323f..118228a40c 100644 --- a/src/nvim/eval/executor.c +++ b/src/nvim/eval/executor.c @@ -25,7 +25,7 @@ char *e_listidx = N_("E684: list index out of range: %" PRId64); /// @return OK or FAIL. int eexe_mod_op(typval_T *const tv1, const typval_T *const tv2, const char *const op) - FUNC_ATTR_NONNULL_ALL + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NO_SANITIZE_UNDEFINED { // Can't do anything with a Funcref, a Dict or special value on the right. if (tv2->v_type != VAR_FUNC && tv2->v_type != VAR_DICT) { -- cgit From b3129b37917f54eb056033a41d1acbb920a5b93b Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sat, 6 May 2017 22:45:26 -0400 Subject: eexe_mod_op: Explicitly cast varnumber_T to float_T for -Wconversion --- src/nvim/eval/executor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/executor.c b/src/nvim/eval/executor.c index 118228a40c..99298cbbcf 100644 --- a/src/nvim/eval/executor.c +++ b/src/nvim/eval/executor.c @@ -55,7 +55,7 @@ int eexe_mod_op(typval_T *const tv1, const typval_T *const tv2, // nr += nr or nr -= nr varnumber_T n = tv_get_number(tv1); if (tv2->v_type == VAR_FLOAT) { - float_T f = n; + float_T f = (float_T)n; if (*op == '+') { f += tv2->vval.v_float; @@ -99,7 +99,7 @@ int eexe_mod_op(typval_T *const tv1, const typval_T *const tv2, } const float_T f = (tv2->v_type == VAR_FLOAT ? tv2->vval.v_float - : tv_get_number(tv2)); + : (float_T)tv_get_number(tv2)); if (*op == '+') { tv1->vval.v_float += f; } else { -- cgit From 2109fb18e663e0ab1e47fa9093713a4e9d8c4932 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Tue, 6 Jun 2017 07:56:03 -0400 Subject: eval/typval: Convert string to varnumber_T instead of intermediate long --- src/nvim/eval/typval.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index f017f57b12..34fb319d76 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -2405,9 +2405,7 @@ varnumber_T tv_get_number_chk(const typval_T *const tv, bool *const ret_error) case VAR_STRING: { varnumber_T n = 0; if (tv->vval.v_string != NULL) { - long nr; - vim_str2nr(tv->vval.v_string, NULL, NULL, STR2NR_ALL, &nr, NULL, 0); - n = (varnumber_T)nr; + vim_str2nr(tv->vval.v_string, NULL, NULL, STR2NR_ALL, &n, NULL, 0); } return n; } -- cgit From af59a290d8fb22a1b33be39c2fe1a6ab6848ee6d Mon Sep 17 00:00:00 2001 From: James McCoy Date: Tue, 6 Jun 2017 14:30:48 -0400 Subject: *: Fix conversion warnings for tv_get_number*() --- src/nvim/eval/typval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 34fb319d76..4521085519 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -2442,7 +2442,7 @@ varnumber_T tv_get_number_chk(const typval_T *const tv, bool *const ret_error) linenr_T tv_get_lnum(const typval_T *const tv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { - linenr_T lnum = tv_get_number_chk(tv, NULL); + linenr_T lnum = (linenr_T)tv_get_number_chk(tv, NULL); if (lnum == 0) { // No valid number, try using same function as line() does. int fnum; pos_T *const fp = var2fpos(tv, true, &fnum); -- cgit