From f8f82901cdd0ccd5308e05c73af6deb7d083720f Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 1 Feb 2023 12:54:22 +0100 Subject: fix(tests): fixes for using vim.mpack and more ASAN --- src/mpack/lmpack.c | 16 ++++++++-------- src/mpack/object.c | 11 ++++++++--- 2 files changed, 16 insertions(+), 11 deletions(-) (limited to 'src/mpack') diff --git a/src/mpack/lmpack.c b/src/mpack/lmpack.c index 53d7092a0c..957bac37cc 100644 --- a/src/mpack/lmpack.c +++ b/src/mpack/lmpack.c @@ -644,7 +644,13 @@ static void lmpack_unparse_enter(mpack_parser_t *parser, mpack_node_t *node) mpack_node_t *n; int has_meta = lua_getmetatable(L, -1); - if (packer->ext != LUA_NOREF && has_meta) { + int has_mtdict = false; + if (has_meta && packer->mtdict != LUA_NOREF) { + lmpack_geti(L, packer->reg, packer->mtdict); // [table, metatable, mtdict] + has_mtdict = lua_rawequal(L, -1, -2); + lua_pop(L, 1); // [table, metatable]; + } + if (packer->ext != LUA_NOREF && has_meta && !has_mtdict) { /* check if there's a handler for this metatable */ lmpack_geti(L, packer->reg, packer->ext); lua_pushvalue(L, -2); @@ -701,14 +707,7 @@ static void lmpack_unparse_enter(mpack_parser_t *parser, mpack_node_t *node) } } - int is_array = 1; if (has_meta) { - // stack: [table, metatable] - if (packer->mtdict != LUA_NOREF) { - lmpack_geti(L, packer->reg, packer->mtdict); // [table, metatable, mtdict] - is_array = !lua_rawequal(L, -1, -2); - lua_pop(L, 1); // [table, metatable]; - } lua_pop(L, 1); // [table] } @@ -726,6 +725,7 @@ static void lmpack_unparse_enter(mpack_parser_t *parser, mpack_node_t *node) lua_pop(L, 1); } + int is_array = !has_mtdict; len = lmpack_objlen(L, &is_array); if (is_array) { node->tok = mpack_pack_array(len); diff --git a/src/mpack/object.c b/src/mpack/object.c index e2d893bc88..60f49f73aa 100644 --- a/src/mpack/object.c +++ b/src/mpack/object.c @@ -128,8 +128,11 @@ MPACK_API int mpack_unparse(mpack_parser_t *parser, char **buf, size_t *buflen, return status; } -MPACK_API void mpack_parser_copy(mpack_parser_t *dst, mpack_parser_t *src) +MPACK_API void mpack_parser_copy(mpack_parser_t *d, mpack_parser_t *s) { + // workaround UBSAN being NOT happy with a flexible array member with arr[N>1] initial size + mpack_one_parser_t *dst = (mpack_one_parser_t *)d; + mpack_one_parser_t *src = (mpack_one_parser_t *)s; mpack_uint32_t i; mpack_uint32_t dst_capacity = dst->capacity; assert(src->capacity <= dst_capacity); @@ -148,8 +151,9 @@ static int mpack_parser_full(mpack_parser_t *parser) return parser->size == parser->capacity; } -static mpack_node_t *mpack_parser_push(mpack_parser_t *parser) +static mpack_node_t *mpack_parser_push(mpack_parser_t *p) { + mpack_one_parser_t *parser = (mpack_one_parser_t *)p; mpack_node_t *top; assert(parser->size < parser->capacity); top = parser->items + parser->size + 1; @@ -162,8 +166,9 @@ static mpack_node_t *mpack_parser_push(mpack_parser_t *parser) return top; } -static mpack_node_t *mpack_parser_pop(mpack_parser_t *parser) +static mpack_node_t *mpack_parser_pop(mpack_parser_t *p) { + mpack_one_parser_t *parser = (mpack_one_parser_t *)p; mpack_node_t *top, *parent; assert(parser->size); top = parser->items + parser->size; -- cgit From 1e60e8c0406f6b4b51c51abb5f53e25bd52fee5e Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 15 Apr 2023 12:23:45 +0200 Subject: refactor(build): use vendored versions of mpack and luabitop --- src/mpack/lmpack.c | 3 +++ src/mpack/lmpack.h | 3 +++ 2 files changed, 6 insertions(+) (limited to 'src/mpack') diff --git a/src/mpack/lmpack.c b/src/mpack/lmpack.c index 957bac37cc..8b45136cae 100644 --- a/src/mpack/lmpack.c +++ b/src/mpack/lmpack.c @@ -1171,6 +1171,9 @@ static const luaL_reg mpack_functions[] = { {NULL, NULL} }; +#ifdef NLUA_WIN32 + __declspec(dllexport) +#endif int luaopen_mpack(lua_State *L) { /* Unpacker */ diff --git a/src/mpack/lmpack.h b/src/mpack/lmpack.h index e35f40fab6..84f786cc8f 100644 --- a/src/mpack/lmpack.h +++ b/src/mpack/lmpack.h @@ -1,3 +1,6 @@ #include +#ifdef NLUA_WIN32 + __declspec(dllexport) +#endif int luaopen_mpack(lua_State *L); -- cgit From ffaf74f1477d3182ffc70bcc9913effc44c90ea7 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 20 Apr 2023 14:41:47 +0200 Subject: fix(build): distinguish vim.mpack from global require'mpack' problem: the api of vim.mpack is not compatible with a system provided mpack solution: don't require 'mpack' directly from the system path --- src/mpack/lmpack.c | 3 --- src/mpack/lmpack.h | 3 --- 2 files changed, 6 deletions(-) (limited to 'src/mpack') diff --git a/src/mpack/lmpack.c b/src/mpack/lmpack.c index 8b45136cae..957bac37cc 100644 --- a/src/mpack/lmpack.c +++ b/src/mpack/lmpack.c @@ -1171,9 +1171,6 @@ static const luaL_reg mpack_functions[] = { {NULL, NULL} }; -#ifdef NLUA_WIN32 - __declspec(dllexport) -#endif int luaopen_mpack(lua_State *L) { /* Unpacker */ diff --git a/src/mpack/lmpack.h b/src/mpack/lmpack.h index 84f786cc8f..e35f40fab6 100644 --- a/src/mpack/lmpack.h +++ b/src/mpack/lmpack.h @@ -1,6 +1,3 @@ #include -#ifdef NLUA_WIN32 - __declspec(dllexport) -#endif int luaopen_mpack(lua_State *L); -- cgit From 307a7abf86c439177910d05003a81ea4a13d2650 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Mon, 9 Oct 2023 11:29:21 +0200 Subject: build(deps): bump libmpack-lua to 1.0.11 update vendored libmpack-lua to match https://github.com/libmpack/libmpack-lua/releases/tag/1.0.11 --- src/mpack/lmpack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mpack') diff --git a/src/mpack/lmpack.c b/src/mpack/lmpack.c index 957bac37cc..3c7108a337 100644 --- a/src/mpack/lmpack.c +++ b/src/mpack/lmpack.c @@ -233,7 +233,7 @@ static mpack_uint32_t lmpack_objlen(lua_State *L, int *is_array) while (lua_next(L, -2)) { lua_pop(L, 1); /* pop value */ isarr = isarr - && lua_isnumber(L, -1) /* lua number */ + && lua_type(L, -1) == LUA_TNUMBER /* lua number */ && (n = lua_tonumber(L, -1)) > 0 /* greater than 0 */ && (size_t)n == n; /* and integer */ max = isarr && (size_t)n > max ? (size_t)n : max; -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/mpack/conv.c | 3 --- src/mpack/lmpack.c | 5 +---- src/mpack/mpack_core.c | 3 --- src/mpack/object.c | 3 --- src/mpack/rpc.c | 3 --- 5 files changed, 1 insertion(+), 16 deletions(-) (limited to 'src/mpack') diff --git a/src/mpack/conv.c b/src/mpack/conv.c index 6bd446ca49..c53ce1427f 100644 --- a/src/mpack/conv.c +++ b/src/mpack/conv.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include "conv.h" static int mpack_fits_single(double v); diff --git a/src/mpack/lmpack.c b/src/mpack/lmpack.c index 3c7108a337..6e693bcc5d 100644 --- a/src/mpack/lmpack.c +++ b/src/mpack/lmpack.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - /* * This module exports three classes, and each instance of those classes has its * own private registry for temporary reference storage(keeping state between @@ -246,7 +243,7 @@ static mpack_uint32_t lmpack_objlen(lua_State *L, int *is_array) } end: - if ((size_t)-1 > (mpack_uint32_t)-1 && len > (mpack_uint32_t)-1) // -V560 + if ((size_t)-1 > (mpack_uint32_t)-1 && len > (mpack_uint32_t)-1) /* msgpack spec doesn't allow lengths > 32 bits */ len = (mpack_uint32_t)-1; assert(top == lua_gettop(L)); diff --git a/src/mpack/mpack_core.c b/src/mpack/mpack_core.c index 3424f444b9..b9b92523bd 100644 --- a/src/mpack/mpack_core.c +++ b/src/mpack/mpack_core.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include #include "mpack_core.h" diff --git a/src/mpack/object.c b/src/mpack/object.c index 60f49f73aa..ec128690d7 100644 --- a/src/mpack/object.c +++ b/src/mpack/object.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include #include "object.h" diff --git a/src/mpack/rpc.c b/src/mpack/rpc.c index 2d251284ba..3b2b328065 100644 --- a/src/mpack/rpc.c +++ b/src/mpack/rpc.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include #include "rpc.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/mpack/lmpack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mpack') diff --git a/src/mpack/lmpack.c b/src/mpack/lmpack.c index 6e693bcc5d..ff21e29789 100644 --- a/src/mpack/lmpack.c +++ b/src/mpack/lmpack.c @@ -24,7 +24,7 @@ #include #include -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "lmpack.h" -- cgit