From dbb03e30881986d78a7f252943ef1f15c06aa213 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sat, 29 Aug 2026 00:38:09 +0200 Subject: [PATCH] Fix UB memcpy + Fix build --- .../Include/Engine/Sasquatch/Sasquatch.hpp | 4 +++- Bigfoot/Sources/Engine/Sasquatch/Sasquatch.cpp | 16 +++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Bigfoot/Sources/Engine/Include/Engine/Sasquatch/Sasquatch.hpp b/Bigfoot/Sources/Engine/Include/Engine/Sasquatch/Sasquatch.hpp index fc23ee4..cbe84f5 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/Sasquatch/Sasquatch.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/Sasquatch/Sasquatch.hpp @@ -12,6 +12,8 @@ #include #include +#include + #include #include #include @@ -97,7 +99,7 @@ class SasquatchWriter /** * The number of assets expected */ - std::uint64_t m_assetCount; + BIGFOOT_NOT_OPTIMIZED_ONLY(std::uint64_t m_assetCount); /** * The offset the next WriteAsset call will write to diff --git a/Bigfoot/Sources/Engine/Sasquatch/Sasquatch.cpp b/Bigfoot/Sources/Engine/Sasquatch/Sasquatch.cpp index bac5c34..ff241f2 100644 --- a/Bigfoot/Sources/Engine/Sasquatch/Sasquatch.cpp +++ b/Bigfoot/Sources/Engine/Sasquatch/Sasquatch.cpp @@ -17,7 +17,7 @@ namespace Bigfoot SasquatchWriter::SasquatchWriter(const File& p_file, const std::uint64_t p_assetCount, const std::size_t p_totalFlatbufferBytes): - m_assetCount(p_assetCount), + BIGFOOT_NOT_OPTIMIZED_ONLY(m_assetCount(p_assetCount),) m_nextOffset(sizeof(SasquatchHeader) + p_assetCount * sizeof(SasquatchEntry)), m_prefetchedUpTo(0), m_file(p_file, m_nextOffset + p_totalFlatbufferBytes) @@ -42,9 +42,12 @@ SasquatchWriter::~SasquatchWriter() m_file.Prefetch(sizeof(SasquatchHeader), m_entries.size() * sizeof(SasquatchEntry)); - std::memcpy(m_file.GetData().data() + sizeof(SasquatchHeader), - m_entries.data(), - m_entries.size() * sizeof(SasquatchEntry)); + if (!m_entries.empty()) + { + std::memcpy(m_file.GetData().data() + sizeof(SasquatchHeader), + m_entries.data(), + m_entries.size() * sizeof(SasquatchEntry)); + } } /****************************************************************************************/ @@ -118,7 +121,10 @@ Sasquatch::Sasquatch(const File& p_file): sizeof(SasquatchHeader) + header.m_assetCount * sizeof(SasquatchEntry)); eastl::vector entries(header.m_assetCount); - std::memcpy(entries.data(), data.data() + sizeof(SasquatchHeader), entries.size() * sizeof(SasquatchEntry)); + if (!entries.empty()) + { + std::memcpy(entries.data(), data.data() + sizeof(SasquatchHeader), entries.size() * sizeof(SasquatchEntry)); + } m_entries.reserve(header.m_assetCount); for (const SasquatchEntry& entry: entries)