aboutsummaryrefslogtreecommitdiff
path: root/src/mpack
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-11-30 20:35:25 +0000
committerJosh Rahm <joshuarahm@gmail.com>2023-11-30 20:35:25 +0000
commit1b7b916b7631ddf73c38e3a0070d64e4636cb2f3 (patch)
treecd08258054db80bb9a11b1061bb091c70b76926a /src/mpack
parenteaa89c11d0f8aefbb512de769c6c82f61a8baca3 (diff)
parent4a8bf24ac690004aedf5540fa440e788459e5e34 (diff)
downloadrneovim-aucmd_textputpost.tar.gz
rneovim-aucmd_textputpost.tar.bz2
rneovim-aucmd_textputpost.zip
Merge remote-tracking branch 'upstream/master' into aucmd_textputpostaucmd_textputpost
Diffstat (limited to 'src/mpack')
-rw-r--r--src/mpack/conv.c3
-rw-r--r--src/mpack/lmpack.c25
-rw-r--r--src/mpack/mpack_core.c3
-rw-r--r--src/mpack/object.c14
-rw-r--r--src/mpack/rpc.c3
5 files changed, 19 insertions, 29 deletions
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 53d7092a0c..ff21e29789 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
@@ -27,7 +24,7 @@
#include <lua.h>
#include <luaconf.h>
-#include "nvim/macros.h"
+#include "nvim/macros_defs.h"
#include "lmpack.h"
@@ -233,7 +230,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;
@@ -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));
@@ -644,7 +641,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 +704,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 +722,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/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 <string.h>
#include "mpack_core.h"
diff --git a/src/mpack/object.c b/src/mpack/object.c
index e2d893bc88..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 <string.h>
#include "object.h"
@@ -128,8 +125,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 +148,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 +163,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;
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 <string.h>
#include "rpc.h"