mirror of https://github.com/AxioDL/metaforce.git
CAudioGroupSet: Eliminate undefined behavior within LoadData()
Eliminates aliasing violations.
This commit is contained in:
parent
855fc0ced9
commit
985b85d9db
|
@ -1,23 +1,31 @@
|
||||||
#include "Runtime/Audio/CAudioGroupSet.hpp"
|
#include "Runtime/Audio/CAudioGroupSet.hpp"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
namespace urde {
|
namespace urde {
|
||||||
|
|
||||||
amuse::AudioGroupData CAudioGroupSet::LoadData() {
|
amuse::AudioGroupData CAudioGroupSet::LoadData() {
|
||||||
|
const auto readU32 = [](const u8* ptr) {
|
||||||
|
uint32_t value;
|
||||||
|
std::memcpy(&value, ptr, sizeof(value));
|
||||||
|
return hecl::SBig(value);
|
||||||
|
};
|
||||||
|
|
||||||
athena::io::MemoryReader r(m_buffer.get(), INT32_MAX);
|
athena::io::MemoryReader r(m_buffer.get(), INT32_MAX);
|
||||||
x10_baseName = r.readString();
|
x10_baseName = r.readString();
|
||||||
x20_name = r.readString();
|
x20_name = r.readString();
|
||||||
|
|
||||||
u8* buf = m_buffer.get() + r.position();
|
u8* buf = m_buffer.get() + r.position();
|
||||||
uint32_t poolLen = hecl::SBig(*reinterpret_cast<uint32_t*>(buf));
|
const uint32_t poolLen = readU32(buf);
|
||||||
unsigned char* pool = buf + 4;
|
unsigned char* pool = buf + 4;
|
||||||
buf += poolLen + 4;
|
buf += poolLen + 4;
|
||||||
uint32_t projLen = hecl::SBig(*reinterpret_cast<uint32_t*>(buf));
|
const uint32_t projLen = readU32(buf);
|
||||||
unsigned char* proj = buf + 4;
|
unsigned char* proj = buf + 4;
|
||||||
buf += projLen + 4;
|
buf += projLen + 4;
|
||||||
uint32_t sampLen = hecl::SBig(*reinterpret_cast<uint32_t*>(buf));
|
const uint32_t sampLen = readU32(buf);
|
||||||
unsigned char* samp = buf + 4;
|
unsigned char* samp = buf + 4;
|
||||||
buf += sampLen + 4;
|
buf += sampLen + 4;
|
||||||
uint32_t sdirLen = hecl::SBig(*reinterpret_cast<uint32_t*>(buf));
|
const uint32_t sdirLen = readU32(buf);
|
||||||
unsigned char* sdir = buf + 4;
|
unsigned char* sdir = buf + 4;
|
||||||
|
|
||||||
return {proj, projLen, pool, poolLen, sdir, sdirLen, samp, sampLen, amuse::GCNDataTag{}};
|
return {proj, projLen, pool, poolLen, sdir, sdirLen, samp, sampLen, amuse::GCNDataTag{}};
|
||||||
|
|
Loading…
Reference in New Issue