From d0fbbeecbe12aeaeb696ee4957dcf96eaf72fe42 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 4 Dec 2024 23:32:22 +0300 Subject: [PATCH 1/2] fix random fatal error in socket:recv --- src/logic/scripting/lua/libs/libnetwork.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/logic/scripting/lua/libs/libnetwork.cpp b/src/logic/scripting/lua/libs/libnetwork.cpp index 61d44de7..dc752710 100644 --- a/src/logic/scripting/lua/libs/libnetwork.cpp +++ b/src/logic/scripting/lua/libs/libnetwork.cpp @@ -101,7 +101,8 @@ static int l_recv(lua::State* L) { if (connection == nullptr) { return 0; } - util::Buffer buffer(glm::min(length, connection->available())); + length = glm::min(length, connection->available()); + util::Buffer buffer(length); int size = connection->recv(buffer.data(), length); if (size == -1) { From f4b80b17405ad9eab3dbcb3901a22c77f5f37b07 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 5 Dec 2024 14:42:33 +0300 Subject: [PATCH 2/2] fix incorrect virtual inventory id in scripting --- src/items/Inventories.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/items/Inventories.cpp b/src/items/Inventories.cpp index d3af607d..4d2baa36 100644 --- a/src/items/Inventories.cpp +++ b/src/items/Inventories.cpp @@ -20,7 +20,9 @@ std::shared_ptr Inventories::create(size_t size) { std::shared_ptr Inventories::createVirtual(size_t size) { int64_t id; do { - id = -std::max(1LL, std::llabs(random.rand64())); + // lua does not support long integers because Number is floating-point + // type. Changing int_consumer to use 64 bit integer does not change anything + id = -std::max(1LL, std::llabs(random.rand64() % 1000'000'000)); } while (map.find(id) != map.end()); auto inv = std::make_shared(id, size);