From b7da56c2df98ea59b4843bc2becc75600ded1724 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 28 Mar 2024 20:22:40 +0100 Subject: [PATCH] Extract the correct number of values when loading a cached data file --- src/data/dataloader.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/data/dataloader.cpp b/src/data/dataloader.cpp index bf3c16bae7..5627d3a4a8 100644 --- a/src/data/dataloader.cpp +++ b/src/data/dataloader.cpp @@ -272,7 +272,11 @@ std::optional loadCachedFile(const std::filesystem::path& path) { int valuesIdx = 0; for (Dataset::Entry& e : result.entries) { e.data.resize(nValues); - std::memcpy(e.data.data(), entriesBuffer.data() + valuesIdx, nValues); + std::memcpy( + e.data.data(), + entriesBuffer.data() + valuesIdx, + nValues * sizeof(float) + ); valuesIdx += nValues; if (e.comment.has_value()) { @@ -283,7 +287,7 @@ std::optional loadCachedFile(const std::filesystem::path& path) { std::memcpy(e.comment->data(), &commentBuffer[commentIdx], e.comment->size()); // and then advance the index - commentIdx += e.comment->size(); + commentIdx += static_cast(e.comment->size()); } } @@ -354,8 +358,9 @@ void saveCachedFile(const Dataset& dataset, const std::filesystem::path& path) { // We assume the number of values for each dataset to be the same, so we can store // them upfront - uint16_t nValues = dataset.entries.empty() ? 0 : dataset.entries[0].data.size(); - checkSize(nValues, "Too many data variables"); + size_t nValuesF = dataset.entries.empty() ? 0 : dataset.entries[0].data.size(); + checkSize(nValuesF, "Too many data variables"); + uint16_t nValues = static_cast(nValuesF); std::vector valuesBuffer; valuesBuffer.reserve(dataset.entries.size() * nValues);