From 68a6460407c60a6f85dd4aff4cd95eb60c8bbd51 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 15 May 2026 22:20:35 +0200 Subject: [PATCH] Fix valgrind warnings (#806) * SDL_Event::timestamp must be initialized to zero or current time. Zero the complete struct to be safe. * Avoid ::strcpy of uninitialized WorldContainer::m_key * Initialize members to avoid uninitialized member accesses --- LEGO1/lego/legoomni/include/legomain.h | 3 ++- LEGO1/lego/legoomni/src/build/legocarbuild.cpp | 1 + .../legoomni/src/common/legoanimationmanager.cpp | 2 ++ LEGO1/lego/legoomni/src/common/legoutils.cpp | 2 +- .../lego/legoomni/src/entity/legoworldpresenter.cpp | 5 +++-- LEGO1/lego/legoomni/src/worlds/hospital.cpp | 5 +++-- LEGO1/omni/include/mxpresenter.h | 2 +- LEGO1/omni/src/stream/mxdiskstreamcontroller.cpp | 2 ++ miniwin/src/ddraw/framebuffer.cpp | 4 ++-- miniwin/src/internal/d3drmrenderer_opengles2.h | 8 ++++---- miniwin/src/internal/d3drmrenderer_opengles3.h | 12 ++++++------ 11 files changed, 27 insertions(+), 19 deletions(-) diff --git a/LEGO1/lego/legoomni/include/legomain.h b/LEGO1/lego/legoomni/include/legomain.h index 8fdf9ecb..c635d60f 100644 --- a/LEGO1/lego/legoomni/include/legomain.h +++ b/LEGO1/lego/legoomni/include/legomain.h @@ -72,6 +72,7 @@ class LegoOmni : public MxOmni { WorldContainer() { m_id = e_undefined; + m_key[0] = '\0'; m_atomId = NULL; } @@ -200,7 +201,7 @@ class LegoOmni : public MxOmni { quit.type = SDL_EVENT_QUIT; quit.timestamp = SDL_GetTicksNS(); - SDL_Event event; + SDL_Event event = {}; event.quit = quit; SDL_PushEvent(&event); diff --git a/LEGO1/lego/legoomni/src/build/legocarbuild.cpp b/LEGO1/lego/legoomni/src/build/legocarbuild.cpp index 08dc3769..4d459473 100644 --- a/LEGO1/lego/legoomni/src/build/legocarbuild.cpp +++ b/LEGO1/lego/legoomni/src/build/legocarbuild.cpp @@ -130,6 +130,7 @@ LegoCarBuild::LegoCarBuild() m_destLocation = LegoGameState::e_undefined; m_playingActorScript = DS_NOT_A_STREAM; m_alreadyFinished = 0; + m_lastActorScript = 0; NotificationManager()->Register(this); } diff --git a/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp b/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp index 6f9cb71d..0238dc6c 100644 --- a/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp +++ b/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp @@ -331,6 +331,8 @@ LegoAnimationManager::LegoAnimationManager() m_animState = NULL; m_unk0x424 = NULL; + ::memset(m_extras, 0, sizeof(m_extras)); + Init(); NotificationManager()->Register(this); diff --git a/LEGO1/lego/legoomni/src/common/legoutils.cpp b/LEGO1/lego/legoomni/src/common/legoutils.cpp index bd403600..6cb10de9 100644 --- a/LEGO1/lego/legoomni/src/common/legoutils.cpp +++ b/LEGO1/lego/legoomni/src/common/legoutils.cpp @@ -592,7 +592,7 @@ void EnableAnimations(MxBool p_enable) // FUNCTION: LEGO1 0x1003ef40 void SetAppCursor(Cursor p_cursor) { - SDL_Event event; + SDL_Event event = {}; event.user.type = g_legoSdlEvents.m_windowsMessage; event.user.code = WM_ISLE_SETCURSOR; event.user.data1 = (void*) p_cursor; diff --git a/LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp b/LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp index aa7d4b87..3d64de1b 100644 --- a/LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp +++ b/LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp @@ -439,10 +439,11 @@ void LegoWorldPresenter::ParseExtra() extraCopy[extraLength] = '\0'; char output[1024]; + output[0] = '\0'; if (KeyValueStringParse(output, g_strWORLD, extraCopy)) { char* worldKey = strtok(output, g_parseExtraTokens); - LoadWorld(worldKey, (LegoWorld*) m_entity); - ((LegoWorld*) m_entity)->SetWorldId(Lego()->GetWorldId(worldKey)); + LoadWorld(worldKey, static_cast(m_entity)); + static_cast(m_entity)->SetWorldId(Lego()->GetWorldId(worldKey)); } } } diff --git a/LEGO1/lego/legoomni/src/worlds/hospital.cpp b/LEGO1/lego/legoomni/src/worlds/hospital.cpp index cd75e1a1..c81e610e 100644 --- a/LEGO1/lego/legoomni/src/worlds/hospital.cpp +++ b/LEGO1/lego/legoomni/src/worlds/hospital.cpp @@ -80,9 +80,9 @@ MxResult Hospital::Create(MxDSAction& p_dsAction) SetIsWorldActive(FALSE); - m_hospitalState = (HospitalState*) GameState()->GetState("HospitalState"); + m_hospitalState = static_cast(GameState()->GetState("HospitalState")); if (!m_hospitalState) { - m_hospitalState = (HospitalState*) GameState()->CreateState("HospitalState"); + m_hospitalState = static_cast(GameState()->CreateState("HospitalState")); m_hospitalState->m_state = HospitalState::e_newState; } else if (m_hospitalState->m_state == HospitalState::e_unknown4) { @@ -676,6 +676,7 @@ MxBool Hospital::Escape() // FUNCTION: LEGO1 0x10076370 HospitalState::HospitalState() { + m_state = e_newState; m_stateActor = 0; m_statePepper = 0; m_stateMama = 0; diff --git a/LEGO1/omni/include/mxpresenter.h b/LEGO1/omni/include/mxpresenter.h index c3b7a216..eb74c3c3 100644 --- a/LEGO1/omni/include/mxpresenter.h +++ b/LEGO1/omni/include/mxpresenter.h @@ -66,7 +66,7 @@ class MxPresenter : public MxCore { m_previousTickleStates |= 1 << (MxU8) m_currentTickleState; m_currentTickleState = p_tickleState; - SDL_Event event; + SDL_Event event = {}; event.user.type = g_legoSdlEvents.m_presenterProgress; event.user.code = m_currentTickleState; event.user.data1 = (void*) m_action; diff --git a/LEGO1/omni/src/stream/mxdiskstreamcontroller.cpp b/LEGO1/omni/src/stream/mxdiskstreamcontroller.cpp index 04f06b63..9aa54440 100644 --- a/LEGO1/omni/src/stream/mxdiskstreamcontroller.cpp +++ b/LEGO1/omni/src/stream/mxdiskstreamcontroller.cpp @@ -15,6 +15,8 @@ DECOMP_SIZE_ASSERT(MxDiskStreamController, 0xc8); // FUNCTION: LEGO1 0x100c7120 MxDiskStreamController::MxDiskStreamController() { + m_unk0xc4 = FALSE; + m_unk0x70 = FALSE; m_unk0x8c = 0; } diff --git a/miniwin/src/ddraw/framebuffer.cpp b/miniwin/src/ddraw/framebuffer.cpp index 067596cd..a913a39e 100644 --- a/miniwin/src/ddraw/framebuffer.cpp +++ b/miniwin/src/ddraw/framebuffer.cpp @@ -234,10 +234,10 @@ HRESULT FrameBufferImpl::SetPalette(LPDIRECTDRAWPALETTE lpDDPalette) } m_palette = lpDDPalette; - SDL_SetSurfacePalette(m_transferBuffer->m_surface, ((DirectDrawPaletteImpl*) m_palette)->m_palette); + SDL_SetSurfacePalette(m_transferBuffer->m_surface, static_cast(m_palette)->m_palette); if (DDRenderer) { - DDRenderer->SetPalette(((DirectDrawPaletteImpl*) m_palette)->m_palette); + DDRenderer->SetPalette(static_cast(m_palette)->m_palette); } return DD_OK; diff --git a/miniwin/src/internal/d3drmrenderer_opengles2.h b/miniwin/src/internal/d3drmrenderer_opengles2.h index fb0e76ac..dfbbe13d 100644 --- a/miniwin/src/internal/d3drmrenderer_opengles2.h +++ b/miniwin/src/internal/d3drmrenderer_opengles2.h @@ -84,10 +84,10 @@ class OpenGLES2Renderer : public Direct3DRMRenderer { SDL_GLContext m_context; float m_anisotropic; GLuint m_fbo; - GLuint m_colorTarget; - GLuint m_depthTarget; - GLuint m_shaderProgram; - GLuint m_dummyTexture; + GLuint m_colorTarget = 0; + GLuint m_depthTarget = 0; + GLuint m_shaderProgram = 0; + GLuint m_dummyTexture = 0; GLint m_posLoc; GLint m_normLoc; GLint m_texLoc; diff --git a/miniwin/src/internal/d3drmrenderer_opengles3.h b/miniwin/src/internal/d3drmrenderer_opengles3.h index 419cd5c1..9c798521 100644 --- a/miniwin/src/internal/d3drmrenderer_opengles3.h +++ b/miniwin/src/internal/d3drmrenderer_opengles3.h @@ -93,13 +93,13 @@ class OpenGLES3Renderer : public Direct3DRMRenderer { SDL_GLContext m_context; uint32_t m_msaa; float m_anisotropic; - GLuint m_fbo; - GLuint m_resolveFBO; - GLuint m_colorTarget; + GLuint m_fbo = 0; + GLuint m_resolveFBO = 0; + GLuint m_colorTarget = 0; GLuint m_resolveColor = 0; - GLuint m_depthTarget; - GLuint m_shaderProgram; - GLuint m_dummyTexture; + GLuint m_depthTarget = 0; + GLuint m_shaderProgram = 0; + GLuint m_dummyTexture = 0; GLint m_posLoc; GLint m_normLoc; GLint m_texLoc;