mirror of
https://github.com/neovim/neovim.git
synced 2025-09-30 23:18:33 +00:00
functests: Test for error conditions
During testing found the following bugs: 1. msgpack-gen.lua script is completely unprepared for Float values either in return type or in arguments. Specifically: 1. At the time of writing relevant code FLOAT_OBJ did not exist as well as FLOATING_OBJ, but it would be used by msgpack-gen.lua should return type be Float. I added FLOATING_OBJ macros later because did not know that msgpack-gen.lua uses these _OBJ macros, otherwise it would be FLOAT_OBJ. 2. msgpack-gen.lua should use .data.floating in place of .data.float. But it did not expect that .data subattribute may have name different from lowercased type name. 2. vim_replace_termcodes returned its argument as-is if it receives an empty string (as well as _vim_id*() functions did). But if something in returned argument lives in an allocated memory such action will cause double free: once when freeing arguments, then when freeing return value. It did not cause problems yet because msgpack bindings return empty string as {NULL, 0} and nothing was actually allocated. 3. New code in msgpack-gen.lua popped arguments in reversed order, making lua bindings’ signatures be different from API ones.
This commit is contained in:
@@ -351,7 +351,7 @@ void set_option_to(void *to, int type, String name, Object value, Error *err)
|
||||
#define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER TYPVAL_ENCODE_CONV_NUMBER
|
||||
|
||||
#define TYPVAL_ENCODE_CONV_FLOAT(tv, flt) \
|
||||
kv_push(edata->stack, FLOATING_OBJ((Float)(flt)))
|
||||
kv_push(edata->stack, FLOAT_OBJ((Float)(flt)))
|
||||
|
||||
#define TYPVAL_ENCODE_CONV_STRING(tv, str, len) \
|
||||
do { \
|
||||
|
@@ -27,7 +27,7 @@
|
||||
.type = kObjectTypeInteger, \
|
||||
.data.integer = i })
|
||||
|
||||
#define FLOATING_OBJ(f) ((Object) { \
|
||||
#define FLOAT_OBJ(f) ((Object) { \
|
||||
.type = kObjectTypeFloat, \
|
||||
.data.floating = f })
|
||||
|
||||
|
@@ -139,7 +139,7 @@ String nvim_replace_termcodes(String str, Boolean from_part, Boolean do_lt,
|
||||
{
|
||||
if (str.size == 0) {
|
||||
// Empty string
|
||||
return str;
|
||||
return (String) { .data = NULL, .size = 0 };
|
||||
}
|
||||
|
||||
char *ptr = NULL;
|
||||
@@ -843,7 +843,7 @@ static void write_msg(String message, bool to_err)
|
||||
/// @return its argument.
|
||||
Object _vim_id(Object obj)
|
||||
{
|
||||
return obj;
|
||||
return copy_object(obj);
|
||||
}
|
||||
|
||||
/// Returns array given as argument
|
||||
@@ -856,7 +856,7 @@ Object _vim_id(Object obj)
|
||||
/// @return its argument.
|
||||
Array _vim_id_array(Array arr)
|
||||
{
|
||||
return arr;
|
||||
return copy_object(ARRAY_OBJ(arr)).data.array;
|
||||
}
|
||||
|
||||
/// Returns dictionary given as argument
|
||||
@@ -869,5 +869,18 @@ Array _vim_id_array(Array arr)
|
||||
/// @return its argument.
|
||||
Dictionary _vim_id_dictionary(Dictionary dct)
|
||||
{
|
||||
return dct;
|
||||
return copy_object(DICTIONARY_OBJ(dct)).data.dictionary;
|
||||
}
|
||||
|
||||
/// Returns floating-point value given as argument
|
||||
///
|
||||
/// This API function is used for testing. One should not rely on its presence
|
||||
/// in plugins.
|
||||
///
|
||||
/// @param[in] flt Value to return.
|
||||
///
|
||||
/// @return its argument.
|
||||
Float _vim_id_float(Float flt)
|
||||
{
|
||||
return flt;
|
||||
}
|
||||
|
Reference in New Issue
Block a user