From 23c985ee60bc4be16682c96407af85b4ab4b139c Mon Sep 17 00:00:00 2001 From: Lars Date: Sat, 31 May 2025 12:41:44 -0700 Subject: [PATCH] Use unique_ptr and std::copy --- src/mapblock.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 5f3c5c850..5cc4d07ae 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -4,6 +4,7 @@ #include "mapblock.h" +#include #include #include "map.h" #include "light.h" @@ -310,7 +311,7 @@ void MapBlock::expireIsAirCache() // Renumbers the content IDs (starting at 0 and incrementing) // Note that there's no technical reason why we *have to* renumber the IDs, // but we do it anyway as it also helps compressability. -static void getBlockNodeIdMapping(NameIdMapping *nimap, MapNode *nodes, +static void getBlockNodeIdMapping(NameIdMapping *nimap, const std::unique_ptr &nodes, const NodeDefManager *nodedef, u32 nodecount) { IdIdMapping &mapping = IdIdMapping::giveClearedThreadLocalInstance(); @@ -430,13 +431,12 @@ void MapBlock::serialize(std::ostream &os_compressed, u8 version, bool disk, int if(disk) { const size_t size = m_is_mono_block ? 1 : nodecount; - MapNode *tmp_nodes = new MapNode[size]; - memcpy(tmp_nodes, data, size * sizeof(MapNode)); + auto tmp_nodes = std::make_unique(size); + std::copy(data, data+size, tmp_nodes.get()); getBlockNodeIdMapping(&nimap, tmp_nodes, m_gamedef->ndef(), size); - buf = MapNode::serializeBulk(version, tmp_nodes, nodecount, + buf = MapNode::serializeBulk(version, tmp_nodes.get(), nodecount, content_width, params_width, m_is_mono_block); - delete[] tmp_nodes; // write timestamp and node/id mapping first if (version >= 29) {