Fix remaning UBSAN issues (#115)

This commit is contained in:
Anders Jenbo 2025-05-19 19:02:24 +02:00 committed by GitHub
parent 4e2df63d9c
commit 70536c50bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 37 additions and 12 deletions

View File

@ -9,6 +9,7 @@
#include "mxtimer.h"
#include "mxutilities.h"
#include <SDL3/SDL_log.h>
#include <SDL3/SDL_stdinc.h>
#include <assert.h>
@ -78,7 +79,11 @@ void MxControlPresenter::EndAction()
MxBool MxControlPresenter::FUN_10044270(MxS32 p_x, MxS32 p_y, MxPresenter* p_presenter)
{
assert(p_presenter);
MxStillPresenter* presenter = (MxStillPresenter*) p_presenter;
MxStillPresenter* presenter = dynamic_cast<MxStillPresenter*>(p_presenter);
if (!presenter) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid presenter");
return FALSE;
}
if (m_unk0x4c == 3) {
MxStillPresenter* map = (MxStillPresenter*) m_list.front();

View File

@ -6,6 +6,8 @@
#include "legopathactor.h"
#include "legopathstruct.h"
#include <SDL3/SDL_log.h>
DECOMP_SIZE_ASSERT(LegoPathBoundary, 0x74)
// FUNCTION: LEGO1 0x10056a70
@ -357,8 +359,12 @@ MxU32 LegoPathBoundary::FUN_10057fe0(LegoAnimPresenter* p_presenter)
// TODO: This only seems to match if the type is not the same as the type of the
// key value of the set. Figure out which type the set (or parameter) actually uses.
// Also see call to .find in LegoPathController::FUN_10046050
m_presenters.insert(static_cast<LegoLocomotionAnimPresenter*>(p_presenter));
return 1;
if (auto* locomotionPresenter = dynamic_cast<LegoLocomotionAnimPresenter*>(p_presenter)) {
m_presenters.insert(locomotionPresenter);
return 1;
}
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid locomotion");
return 0;
}
// FUNCTION: LEGO1 0x100586e0
@ -369,8 +375,14 @@ MxU32 LegoPathBoundary::FUN_100586e0(LegoAnimPresenter* p_presenter)
// TODO: This only seems to match if the type is not the same as the type of the
// key value of the set. Figure out which type the set (or parameter) actually uses.
// Also see call to .find in LegoPathController::FUN_10046050
if (m_presenters.find(static_cast<LegoLocomotionAnimPresenter*>(p_presenter)) != m_presenters.end()) {
m_presenters.erase(static_cast<LegoLocomotionAnimPresenter*>(p_presenter));
auto* locomotionPresenter = dynamic_cast<LegoLocomotionAnimPresenter*>(p_presenter);
if (!locomotionPresenter) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid locomotion");
return 0;
}
auto it = m_presenters.find(locomotionPresenter);
if (it != m_presenters.end()) {
m_presenters.erase(it);
return 1;
}
}

View File

@ -93,7 +93,7 @@ void LegoPhonemePresenter::LoadFrame(MxStreamChunk* p_chunk)
{
MxU8* data = p_chunk->GetData();
m_rectCount = *(MxS32*) data;
m_rectCount = UnalignedRead<MxS32>(data);
data += sizeof(MxS32);
MxRect32* rects = (MxRect32*) data;

View File

@ -159,9 +159,10 @@ void WritePixelPairs(
short is_odd = p_count & 1;
p_count >>= 1;
WORD* dst = (WORD*) (((p_bitmapHeader->biWidth + 3) & -4) * p_row + p_column + p_pixelData);
BYTE* dst = ((p_bitmapHeader->biWidth + 3) & -4) * p_row + p_column + p_pixelData;
while (--p_count >= 0) {
*dst++ = p_pixel;
memcpy(dst, &p_pixel, sizeof(WORD));
dst += sizeof(WORD);
}
if (is_odd) {

View File

@ -49,10 +49,10 @@ void MxFlcPresenter::LoadFrame(MxStreamChunk* p_chunk)
{
MxU8* data = p_chunk->GetData();
MxS32 rectCount = *(MxS32*) data;
MxS32 rectCount = UnalignedRead<MxS32>(data);
data += sizeof(MxS32);
MxRect32* rects = (MxRect32*) data;
MxU8* rects = data;
data += rectCount * sizeof(MxRect32);
MxBool decodedColorMap;
@ -69,7 +69,8 @@ void MxFlcPresenter::LoadFrame(MxStreamChunk* p_chunk)
}
for (MxS32 i = 0; i < rectCount; i++) {
MxRect32 rect(rects[i]);
MxRect32 rect = UnalignedRead<MxRect32>(rects);
rects += sizeof(MxRect32);
rect += m_location;
MVideoManager()->InvalidateRect(rect);
}

View File

@ -1,5 +1,7 @@
#include "impl.h"
#include <SDL3/SDL_log.h>
using namespace TglImpl;
// FUNCTION: LEGO1 0x100a31d0
@ -89,7 +91,11 @@ Result GroupImpl::Add(const Group* pGroup)
// FUNCTION: LEGO1 0x100a3430
Result GroupImpl::Add(const MeshBuilder* pMeshBuilder)
{
const MeshBuilderImpl* pMeshBuilderImpl = static_cast<const MeshBuilderImpl*>(pMeshBuilder);
const MeshBuilderImpl* pMeshBuilderImpl = dynamic_cast<const MeshBuilderImpl*>(pMeshBuilder);
if (!pMeshBuilderImpl) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid mesh builder");
return Result::Error;
}
return ResultVal(m_data->AddVisual(pMeshBuilderImpl->ImplementationData()));
}