diff --git a/CONFIG/MainDlg.cpp b/CONFIG/MainDlg.cpp index e2c526f6..d2cc657b 100644 --- a/CONFIG/MainDlg.cpp +++ b/CONFIG/MainDlg.cpp @@ -101,8 +101,9 @@ bool CMainDialog::OnInitDialog() selected = device_i; } device_i += 1; - sprintf( + snprintf( device_name, + sizeof(device_name), "%s ( %s )", device.m_deviceDesc, driver_i == 0 ? "Primary Device" : "Secondary Device" diff --git a/CONFIG/config.cpp b/CONFIG/config.cpp index bd38e669..1fb79963 100644 --- a/CONFIG/config.cpp +++ b/CONFIG/config.cpp @@ -280,7 +280,7 @@ void CConfigApp::WriteRegisterSettings() const #define SetIniBool(DICT, NAME, VALUE) iniparser_set(DICT, NAME, VALUE ? "true" : "false") #define SetIniInt(DICT, NAME, VALUE) \ do { \ - sprintf(buffer, "%d", VALUE); \ + snprintf(buffer, sizeof(buffer), "%d", VALUE); \ iniparser_set(DICT, NAME, buffer); \ } while (0) diff --git a/LEGO1/lego/legoomni/src/actors/act3ammo.cpp b/LEGO1/lego/legoomni/src/actors/act3ammo.cpp index 04e0e93c..de0c5a5e 100644 --- a/LEGO1/lego/legoomni/src/actors/act3ammo.cpp +++ b/LEGO1/lego/legoomni/src/actors/act3ammo.cpp @@ -76,7 +76,7 @@ MxResult Act3Ammo::Create(Act3* p_world, MxU32 p_isPizza, MxS32 p_index) char name[12]; if (p_isPizza) { - sprintf(name, "pammo%d", p_index); + snprintf(name, sizeof(name), "pammo%d", p_index); m_roi = CharacterManager()->CreateAutoROI(name, "pizpie", FALSE); m_roi->SetVisibility(TRUE); @@ -90,7 +90,7 @@ MxResult Act3Ammo::Create(Act3* p_world, MxU32 p_isPizza, MxS32 p_index) assert(m_roi); } else { - sprintf(name, "dammo%d", p_index); + snprintf(name, sizeof(name), "dammo%d", p_index); m_roi = CharacterManager()->CreateAutoROI(name, "donut", FALSE); m_roi->SetVisibility(TRUE); diff --git a/LEGO1/lego/legoomni/src/actors/ambulance.cpp b/LEGO1/lego/legoomni/src/actors/ambulance.cpp index ff87c657..0682ae9a 100644 --- a/LEGO1/lego/legoomni/src/actors/ambulance.cpp +++ b/LEGO1/lego/legoomni/src/actors/ambulance.cpp @@ -94,7 +94,7 @@ void Ambulance::Animate(float p_time) float speed = abs(m_worldSpeed); float maxLinearVel = NavController()->GetMaxLinearVel(); - sprintf(buf, "%g", speed / maxLinearVel); + snprintf(buf, sizeof(buf), "%g", speed / maxLinearVel); VariableTable()->SetVariable(g_varAMBULSPEED, buf); m_fuel += (p_time - m_time) * -3.333333333e-06f; @@ -104,7 +104,7 @@ void Ambulance::Animate(float p_time) m_time = p_time; - sprintf(buf, "%g", m_fuel); + snprintf(buf, sizeof(buf), "%g", m_fuel); VariableTable()->SetVariable(g_varAMBULFUEL, buf); } } diff --git a/LEGO1/lego/legoomni/src/actors/dunebuggy.cpp b/LEGO1/lego/legoomni/src/actors/dunebuggy.cpp index 049c7f86..ffa8c64b 100644 --- a/LEGO1/lego/legoomni/src/actors/dunebuggy.cpp +++ b/LEGO1/lego/legoomni/src/actors/dunebuggy.cpp @@ -59,7 +59,7 @@ void DuneBuggy::Animate(float p_time) float speed = abs(m_worldSpeed); float maxLinearVel = NavController()->GetMaxLinearVel(); - sprintf(buf, "%g", speed / maxLinearVel); + snprintf(buf, sizeof(buf), "%g", speed / maxLinearVel); VariableTable()->SetVariable(g_varDUNESPEED, buf); m_fuel += (p_time - m_time) * -3.333333333e-06f; @@ -69,7 +69,7 @@ void DuneBuggy::Animate(float p_time) m_time = p_time; - sprintf(buf, "%g", m_fuel); + snprintf(buf, sizeof(buf), "%g", m_fuel); VariableTable()->SetVariable(g_varDUNEFUEL, buf); } diff --git a/LEGO1/lego/legoomni/src/actors/jetski.cpp b/LEGO1/lego/legoomni/src/actors/jetski.cpp index 2c57c76e..9a4a0157 100644 --- a/LEGO1/lego/legoomni/src/actors/jetski.cpp +++ b/LEGO1/lego/legoomni/src/actors/jetski.cpp @@ -62,7 +62,7 @@ void Jetski::Animate(float p_time) float speed = abs(m_worldSpeed); float maxLinearVel = NavController()->GetMaxLinearVel(); - sprintf(buf, "%g", speed / maxLinearVel); + snprintf(buf, sizeof(buf), "%g", speed / maxLinearVel); VariableTable()->SetVariable(g_varJETSPEED, buf); } diff --git a/LEGO1/lego/legoomni/src/actors/motorcycle.cpp b/LEGO1/lego/legoomni/src/actors/motorcycle.cpp index 6a20d6f3..8293d5cb 100644 --- a/LEGO1/lego/legoomni/src/actors/motorcycle.cpp +++ b/LEGO1/lego/legoomni/src/actors/motorcycle.cpp @@ -55,7 +55,7 @@ void Motocycle::Animate(float p_time) float speed = abs(m_worldSpeed); float maxLinearVel = NavController()->GetMaxLinearVel(); - sprintf(buf, "%g", speed / maxLinearVel); + snprintf(buf, sizeof(buf), "%g", speed / maxLinearVel); VariableTable()->SetVariable(g_varMOTOSPEED, buf); m_fuel += (p_time - m_time) * -3.333333333e-06f; @@ -65,7 +65,7 @@ void Motocycle::Animate(float p_time) m_time = p_time; - sprintf(buf, "%g", m_fuel); + snprintf(buf, sizeof(buf), "%g", m_fuel); VariableTable()->SetVariable(g_varMOTOFUEL, buf); } } diff --git a/LEGO1/lego/legoomni/src/actors/towtrack.cpp b/LEGO1/lego/legoomni/src/actors/towtrack.cpp index 6143ccf8..31f72c76 100644 --- a/LEGO1/lego/legoomni/src/actors/towtrack.cpp +++ b/LEGO1/lego/legoomni/src/actors/towtrack.cpp @@ -85,7 +85,7 @@ void TowTrack::Animate(float p_time) float speed = abs(m_worldSpeed); float maxLinearVel = NavController()->GetMaxLinearVel(); - sprintf(buf, "%g", speed / maxLinearVel); + snprintf(buf, sizeof(buf), "%g", speed / maxLinearVel); VariableTable()->SetVariable(g_varTOWSPEED, buf); m_fuel += (p_time - m_time) * -3.333333333e-06f; @@ -95,7 +95,7 @@ void TowTrack::Animate(float p_time) m_time = p_time; - sprintf(buf, "%g", m_fuel); + snprintf(buf, sizeof(buf), "%g", m_fuel); VariableTable()->SetVariable(g_varTOWFUEL, buf); if (p_time - m_state->m_startTime > 100000.0f && m_state->m_unk0x08 == 1 && !m_state->m_unk0x10) { diff --git a/LEGO1/lego/legoomni/src/build/legocarbuild.cpp b/LEGO1/lego/legoomni/src/build/legocarbuild.cpp index fa0be996..bbd841ed 100644 --- a/LEGO1/lego/legoomni/src/build/legocarbuild.cpp +++ b/LEGO1/lego/legoomni/src/build/legocarbuild.cpp @@ -1383,7 +1383,7 @@ void LegoCarBuild::FUN_10025350(MxS32 p_objectId) m_Paint_Sound->Enable(FALSE); m_Paint_Sound->Enable(TRUE); m_unk0x110->FUN_100a93b0(color); - sprintf(buffer, "c_%s", m_unk0x110->GetName()); + snprintf(buffer, sizeof(buffer), "c_%s", m_unk0x110->GetName()); VariableTable()->SetVariable(buffer, color); } diff --git a/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp b/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp index 665c6459..21cfb983 100644 --- a/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp +++ b/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp @@ -631,26 +631,26 @@ MxResult LegoAnimationManager::LoadWorldInfo(LegoOmni::World p_worldId) char filename[128]; char path[1024]; - sprintf(filename, "lego\\data\\%sinf.dta", Lego()->GetWorldName(p_worldId)); - sprintf(path, "%s", MxOmni::GetHD()); + snprintf(filename, sizeof(filename), "lego\\data\\%sinf.dta", Lego()->GetWorldName(p_worldId)); + snprintf(path, sizeof(path), "%s", MxOmni::GetHD()); if (path[strlen(path) - 1] != '\\') { - strcat(path, "\\"); + strncat(path, "\\", sizeof(path) - strlen(path) - 1); } - strcat(path, filename); + strncat(path, filename, sizeof(path) - strlen(path) - 1); MxString::MapPathToFilesystem(path); SDL_PathInfo pathInfo; if (!SDL_GetPathInfo(path, &pathInfo) || pathInfo.type != SDL_PATHTYPE_FILE) { - sprintf(path, "%s", MxOmni::GetCD()); + snprintf(path, sizeof(path), "%s", MxOmni::GetCD()); if (path[strlen(path) - 1] != '\\') { - strcat(path, "\\"); + strncat(path, "\\", sizeof(path) - strlen(path) - 1); } - strcat(path, filename); + strncat(path, filename, sizeof(path) - strlen(path) - 1); MxString::MapPathToFilesystem(path); if (!SDL_GetPathInfo(path, &pathInfo) || pathInfo.type != SDL_PATHTYPE_FILE) { @@ -1014,7 +1014,7 @@ MxResult LegoAnimationManager::FUN_100605e0( } char buf[256]; - sprintf(buf, "%s:%d", g_strANIMMAN_ID, tranInfo->m_index); + snprintf(buf, sizeof(buf), "%s:%d", g_strANIMMAN_ID, tranInfo->m_index); action.SetAtomId(*Lego()->GetWorldAtom(m_worldId)); action.SetObjectId(animInfo.m_objectId); @@ -1081,7 +1081,7 @@ MxResult LegoAnimationManager::FUN_100609f0(MxU32 p_objectId, MxMatrix* p_matrix } char buf[256]; - sprintf(buf, "%s:%d", g_strANIMMAN_ID, info->m_index); + snprintf(buf, sizeof(buf), "%s:%d", g_strANIMMAN_ID, info->m_index); action.SetAtomId(*Lego()->GetWorldAtom(m_worldId)); action.SetObjectId(p_objectId); diff --git a/LEGO1/lego/legoomni/src/common/legocharactermanager.cpp b/LEGO1/lego/legoomni/src/common/legocharactermanager.cpp index 6510dcb3..ce3b70c8 100644 --- a/LEGO1/lego/legoomni/src/common/legocharactermanager.cpp +++ b/LEGO1/lego/legoomni/src/common/legocharactermanager.cpp @@ -521,7 +521,7 @@ LegoROI* LegoCharacterManager::CreateActorROI(const char* p_key) ViewLODList* lodList = lodManager->Lookup(parentName); MxS32 lodSize = lodList->Size(); - sprintf(lodName, "%s%d", p_key, i); + snprintf(lodName, sizeof(lodName), "%s%d", p_key, i); ViewLODList* dupLodList = lodManager->Create(lodName, lodSize); for (MxS32 j = 0; j < lodSize; j++) { @@ -616,7 +616,7 @@ MxBool LegoCharacterManager::SetHeadTexture(LegoROI* p_roi, LegoTextureInfo* p_t assert(lodList); MxS32 lodSize = lodList->Size(); - sprintf(lodName, "%s%s%d", p_roi->GetName(), "head", g_headTextureCounter++); + snprintf(lodName, sizeof(lodName), "%s%s%d", p_roi->GetName(), "head", g_headTextureCounter++); ViewLODList* dupLodList = GetViewLODListManager()->Create(lodName, lodSize); assert(dupLodList); @@ -829,7 +829,7 @@ MxBool LegoCharacterManager::SwitchVariant(LegoROI* p_roi) ViewLODList* lodList = GetViewLODListManager()->Lookup(part.m_partName[partNameIndex]); MxS32 lodSize = lodList->Size(); - sprintf(lodName, "%s%d", p_roi->GetName(), g_infohatVariantCounter++); + snprintf(lodName, sizeof(lodName), "%s%d", p_roi->GetName(), g_infohatVariantCounter++); ViewLODList* dupLodList = GetViewLODListManager()->Create(lodName, lodSize); Tgl::Renderer* renderer = VideoManager()->GetRenderer(); @@ -1007,7 +1007,7 @@ LegoROI* LegoCharacterManager::CreateAutoROI(const char* p_name, const char* p_l name = p_name; } else { - sprintf(buf, "autoROI_%d", g_autoRoiCounter++); + snprintf(buf, sizeof(buf), "autoROI_%d", g_autoRoiCounter++); name = buf; } diff --git a/LEGO1/lego/legoomni/src/common/legogamestate.cpp b/LEGO1/lego/legoomni/src/common/legogamestate.cpp index 93665ee3..69b74c59 100644 --- a/LEGO1/lego/legoomni/src/common/legogamestate.cpp +++ b/LEGO1/lego/legoomni/src/common/legogamestate.cpp @@ -577,12 +577,12 @@ void LegoGameState::GetFileSavePath(MxString* p_outPath, MxS16 p_slotn) } // Slot: "G0", "G1", ... - strcat(path, "\\G"); + strncat(path, "\\G", sizeof(path) - strlen(path) - 1); baseForSlot[0] += p_slotn; - strcat(path, baseForSlot); + strncat(path, baseForSlot, sizeof(path) - strlen(path) - 1); // Extension: ".GS" - strcat(path, g_fileExtensionGS); + strncat(path, g_fileExtensionGS, sizeof(path) - strlen(path) - 1); *p_outPath = MxString(path); p_outPath->MapPathToFilesystem(); } @@ -1088,7 +1088,7 @@ MxBool ROIColorOverride(const char* p_input, char* p_output, MxU32 p_copyLen) SDL_strncasecmp(p_input, "INDIR-G-", strlen("INDIR-F-")) == 0)) { char buf[256]; - sprintf(buf, "c_%s", &p_input[strlen("INDIR-F-")]); + snprintf(buf, sizeof(buf), "c_%s", &p_input[strlen("INDIR-F-")]); const char* value = VariableTable()->GetVariable(buf); if (value != NULL) { @@ -1285,7 +1285,7 @@ void LegoBackgroundColor::ToggleDayNight(MxBool p_sun) } } - sprintf(buffer, "set %d %d %d", (MxU32) (m_h * 100.0f), (MxU32) (m_s * 100.0f), (MxU32) (m_v * 100.0f)); + snprintf(buffer, sizeof(buffer), "set %d %d %d", (MxU32) (m_h * 100.0f), (MxU32) (m_s * 100.0f), (MxU32) (m_v * 100.0f)); m_value = buffer; float convertedR, convertedG, convertedB; @@ -1305,7 +1305,7 @@ void LegoBackgroundColor::ToggleSkyColor() m_h -= 1.0; } - sprintf(buffer, "set %d %d %d", (MxU32) (m_h * 100.0f), (MxU32) (m_s * 100.0f), (MxU32) (m_v * 100.0f)); + snprintf(buffer, sizeof(buffer), "set %d %d %d", (MxU32) (m_h * 100.0f), (MxU32) (m_s * 100.0f), (MxU32) (m_v * 100.0f)); m_value = buffer; float convertedR, convertedG, convertedB; diff --git a/LEGO1/lego/legoomni/src/common/legoplantmanager.cpp b/LEGO1/lego/legoomni/src/common/legoplantmanager.cpp index c5b57a17..00375eee 100644 --- a/LEGO1/lego/legoomni/src/common/legoplantmanager.cpp +++ b/LEGO1/lego/legoomni/src/common/legoplantmanager.cpp @@ -222,8 +222,8 @@ LegoEntity* LegoPlantManager::CreatePlant(MxS32 p_index, LegoWorld* p_world, Leg char name[256]; char lodName[256]; - sprintf(name, "plant%d", p_index); - sprintf(lodName, "%s", g_plantLodNames[g_plantInfo[p_index].m_variant][g_plantInfo[p_index].m_color]); + snprintf(name, sizeof(name), "plant%d", p_index); + snprintf(lodName, sizeof(lodName), "%s", g_plantLodNames[g_plantInfo[p_index].m_variant][g_plantInfo[p_index].m_color]); LegoROI* roi = CharacterManager()->CreateAutoROI(name, lodName, TRUE); assert(roi != NULL); diff --git a/LEGO1/lego/legoomni/src/common/legoutils.cpp b/LEGO1/lego/legoomni/src/common/legoutils.cpp index 9d3f3c7d..2fb961f5 100644 --- a/LEGO1/lego/legoomni/src/common/legoutils.cpp +++ b/LEGO1/lego/legoomni/src/common/legoutils.cpp @@ -625,7 +625,7 @@ MxS32 UpdateLightPosition(MxS32 p_increase) SetLightPosition(lightPosition); char lightPositionBuffer[32]; - sprintf(lightPositionBuffer, "%d", lightPosition); + snprintf(lightPositionBuffer, sizeof(lightPositionBuffer), "%d", lightPosition); VariableTable()->SetVariable("lightposition", lightPositionBuffer); diff --git a/LEGO1/lego/legoomni/src/entity/act2brick.cpp b/LEGO1/lego/legoomni/src/entity/act2brick.cpp index 16e0d2eb..61dbd3c8 100644 --- a/LEGO1/lego/legoomni/src/entity/act2brick.cpp +++ b/LEGO1/lego/legoomni/src/entity/act2brick.cpp @@ -49,7 +49,7 @@ MxResult Act2Brick::Create(MxS32 p_index) } char name[12]; - sprintf(name, "chbrick%d", p_index); + snprintf(name, sizeof(name), "chbrick%d", p_index); m_roi = CharacterManager()->CreateAutoROI(name, g_lodNames[p_index], FALSE); assert(m_roi); diff --git a/LEGO1/lego/legoomni/src/entity/legoentity.cpp b/LEGO1/lego/legoomni/src/entity/legoentity.cpp index 148d4c16..93750714 100644 --- a/LEGO1/lego/legoomni/src/entity/legoentity.cpp +++ b/LEGO1/lego/legoomni/src/entity/legoentity.cpp @@ -310,19 +310,19 @@ void LegoEntity::ClickAnimation() case e_actor: objectId = LegoOmni::GetInstance()->GetCharacterManager()->GetAnimationId(m_roi); action.SetAtomId(MxAtomId(LegoCharacterManager::GetCustomizeAnimFile(), e_lowerCase2)); - sprintf(extra, "SUBST:actor_01:%s", name); + snprintf(extra, sizeof(extra), "SUBST:actor_01:%s", name); break; case e_unk1: break; case e_plant: objectId = LegoOmni::GetInstance()->GetPlantManager()->GetAnimationId(this); action.SetAtomId(MxAtomId(LegoPlantManager::GetCustomizeAnimFile(), e_lowerCase2)); - sprintf(extra, "SUBST:bush:%s:tree:%s:flwrred:%s:palm:%s", name, name, name, name); + snprintf(extra, sizeof(extra), "SUBST:bush:%s:tree:%s:flwrred:%s:palm:%s", name, name, name, name); break; case e_building: objectId = LegoOmni::GetInstance()->GetBuildingManager()->GetAnimationId(this); action.SetAtomId(MxAtomId(BuildingManager()->GetCustomizeAnimFile(), e_lowerCase2)); - sprintf(extra, "SUBST:haus1:%s", name); + snprintf(extra, sizeof(extra), "SUBST:haus1:%s", name); break; case e_autoROI: break; diff --git a/LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp b/LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp index 00b877bd..a5c92af4 100644 --- a/LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp +++ b/LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp @@ -165,25 +165,25 @@ void LegoWorldPresenter::StartingTickle() MxResult LegoWorldPresenter::LoadWorld(char* p_worldName, LegoWorld* p_world) { char wdbPath[512]; - sprintf(wdbPath, "%s", MxOmni::GetHD()); + snprintf(wdbPath, sizeof(wdbPath), "%s", MxOmni::GetHD()); if (wdbPath[strlen(wdbPath) - 1] != '\\' && wdbPath[strlen(wdbPath) - 1] != '/') { - strcat(wdbPath, "\\"); + strncat(wdbPath, "\\", sizeof(wdbPath) - strlen(wdbPath) - 1); } - strcat(wdbPath, "lego\\data\\world.wdb"); + strncat(wdbPath, "lego\\data\\world.wdb", sizeof(wdbPath) - strlen(wdbPath) - 1); MxString::MapPathToFilesystem(wdbPath); SDL_IOStream* wdbFile; if ((wdbFile = SDL_IOFromFile(wdbPath, "rb")) == NULL) { - sprintf(wdbPath, "%s", MxOmni::GetCD()); + snprintf(wdbPath, sizeof(wdbPath), "%s", MxOmni::GetCD()); if (wdbPath[strlen(wdbPath) - 1] != '\\' && wdbPath[strlen(wdbPath) - 1] != '/') { - strcat(wdbPath, "\\"); + strncat(wdbPath, "\\", sizeof(wdbPath) - strlen(wdbPath) - 1); } - strcat(wdbPath, "lego\\data\\world.wdb"); + strncat(wdbPath, "lego\\data\\world.wdb", sizeof(wdbPath) - strlen(wdbPath) - 1); MxString::MapPathToFilesystem(wdbPath); if ((wdbFile = SDL_IOFromFile(wdbPath, "rb")) == NULL) { diff --git a/LEGO1/lego/legoomni/src/race/carrace.cpp b/LEGO1/lego/legoomni/src/race/carrace.cpp index 988584c5..84ae71ef 100644 --- a/LEGO1/lego/legoomni/src/race/carrace.cpp +++ b/LEGO1/lego/legoomni/src/race/carrace.cpp @@ -193,7 +193,7 @@ MxLong CarRace::HandlePathStruct(LegoPathStructNotificationParam& p_param) m_unk0x104 = paramData; LegoChar buffer[20]; - sprintf(buffer, "%g", 0.036 + 0.928 * (m_unk0xf8 * 20.0 + m_unk0x104) / (g_unk0x100f0c7c * 20.0)); + snprintf(buffer, sizeof(buffer), "%g", 0.036 + 0.928 * (m_unk0xf8 * 20.0 + m_unk0x104) / (g_unk0x100f0c7c * 20.0)); VariableTable()->SetVariable("DISTANCE", buffer); if (m_unk0x104 == 0x14) { diff --git a/LEGO1/lego/legoomni/src/race/jetskirace.cpp b/LEGO1/lego/legoomni/src/race/jetskirace.cpp index 042090db..17810e7f 100644 --- a/LEGO1/lego/legoomni/src/race/jetskirace.cpp +++ b/LEGO1/lego/legoomni/src/race/jetskirace.cpp @@ -171,7 +171,7 @@ MxLong JetskiRace::HandlePathStruct(LegoPathStructNotificationParam& p_param) m_unk0x104 = paramData; LegoChar buffer[20]; - sprintf(buffer, "%g", 0.032 + 0.936 * (m_unk0xf8 * 20.0 + m_unk0x104) / (g_unk0x100f0c78 * 20.0)); + snprintf(buffer, sizeof(buffer), "%g", 0.032 + 0.936 * (m_unk0xf8 * 20.0 + m_unk0x104) / (g_unk0x100f0c78 * 20.0)); VariableTable()->SetVariable("DISTANCE", buffer); if (m_unk0x104 == 0x14) { diff --git a/LEGO1/lego/legoomni/src/race/legoracers.cpp b/LEGO1/lego/legoomni/src/race/legoracers.cpp index 0cffed0c..665be79b 100644 --- a/LEGO1/lego/legoomni/src/race/legoracers.cpp +++ b/LEGO1/lego/legoomni/src/race/legoracers.cpp @@ -425,7 +425,7 @@ void LegoRaceCar::Animate(float p_time) float maximumSpeed = NavController()->GetMaxLinearVel(); char buffer[200]; - sprintf(buffer, "%g", absoluteSpeed / maximumSpeed); + snprintf(buffer, sizeof(buffer), "%g", absoluteSpeed / maximumSpeed); VariableTable()->SetVariable(g_strSpeed, buffer); @@ -624,7 +624,7 @@ void LegoJetski::Animate(float p_time) float speedRatio = absoluteSpeed / NavController()->GetMaxLinearVel(); char buffer[200]; - sprintf(buffer, "%g", speedRatio); + snprintf(buffer, sizeof(buffer), "%g", speedRatio); VariableTable()->SetVariable(g_strJetSpeed, buffer); diff --git a/LEGO1/lego/legoomni/src/video/legoanimpresenter.cpp b/LEGO1/lego/legoomni/src/video/legoanimpresenter.cpp index 28642bab..5d78db4c 100644 --- a/LEGO1/lego/legoomni/src/video/legoanimpresenter.cpp +++ b/LEGO1/lego/legoomni/src/video/legoanimpresenter.cpp @@ -201,7 +201,7 @@ LegoChar* LegoAnimPresenter::FUN_10069150(const LegoChar* p_und1) } else { LegoChar buffer[32]; - sprintf(buffer, "%d", m_action->GetUnknown24()); + snprintf(buffer, sizeof(buffer), "%d", m_action->GetUnknown24()); str = new LegoChar[strlen(p_und1) + strlen(buffer) + strlen(GetActionObjectName()) + 1]; if (str != NULL) { @@ -343,11 +343,11 @@ LegoChar* LegoAnimPresenter::GetVariableOrIdentity(const LegoChar* p_varName, co *result = '\0'; if (p_prefix) { - strcpy(result, p_prefix); - strcat(result, ":"); + strncpy(result, p_prefix, len); + strncat(result, ":", len - strlen(result) - 1); } - strcat(result, str); + strncat(result, str, len - strlen(result) - 1); } return result; diff --git a/LEGO1/lego/legoomni/src/video/legoflctexturepresenter.cpp b/LEGO1/lego/legoomni/src/video/legoflctexturepresenter.cpp index 9aeabf74..b9f1164d 100644 --- a/LEGO1/lego/legoomni/src/video/legoflctexturepresenter.cpp +++ b/LEGO1/lego/legoomni/src/video/legoflctexturepresenter.cpp @@ -29,8 +29,8 @@ void LegoFlcTexturePresenter::StartingTickle() m_action->GetExtra(extraLength, pp); if (pp != NULL) { - strcpy(extraCopy, pp); - strcat(extraCopy, ".gif"); + strncpy(extraCopy, pp, sizeof(extraCopy)); + strncat(extraCopy, ".gif", sizeof(extraCopy) - strlen(extraCopy) - 1); m_texture = TextureContainer()->Get(extraCopy); } diff --git a/LEGO1/lego/legoomni/src/video/legovideomanager.cpp b/LEGO1/lego/legoomni/src/video/legovideomanager.cpp index a0173224..00773e89 100644 --- a/LEGO1/lego/legoomni/src/video/legovideomanager.cpp +++ b/LEGO1/lego/legoomni/src/video/legovideomanager.cpp @@ -447,7 +447,7 @@ void LegoVideoManager::DrawFPS() if (Timer()->GetTime() > m_unk0x54c + 5000.f) { char buffer[32]; MxFloat time = (Timer()->GetTime() - m_unk0x54c) / 1000.0f; - sprintf(buffer, "%.02f", m_unk0x550 / time); + snprintf(buffer, sizeof(buffer), "%.02f", m_unk0x550 / time); m_unk0x54c = Timer()->GetTime(); DDSURFACEDESC surfaceDesc; diff --git a/LEGO1/lego/legoomni/src/worlds/act3.cpp b/LEGO1/lego/legoomni/src/worlds/act3.cpp index 0166c9d7..07a83a8f 100644 --- a/LEGO1/lego/legoomni/src/worlds/act3.cpp +++ b/LEGO1/lego/legoomni/src/worlds/act3.cpp @@ -600,7 +600,7 @@ MxLong Act3::Notify(MxParam& p_param) char buf[80]; do { - sprintf(buf, "HelicopterDotOn%d_Bitmap", length + 1); + snprintf(buf, sizeof(buf), "HelicopterDotOn%d_Bitmap", length + 1); m_helicopterDots[length] = (MxPresenter*) Find("MxPresenter", buf); if (m_unk0x421e > length) { diff --git a/LEGO1/omni/src/stream/mxdsfile.cpp b/LEGO1/omni/src/stream/mxdsfile.cpp index d083b103..049f6194 100644 --- a/LEGO1/omni/src/stream/mxdsfile.cpp +++ b/LEGO1/omni/src/stream/mxdsfile.cpp @@ -71,7 +71,7 @@ MxResult MxDSFile::ReadChunks() m_io.Read(&m_header, 0x0c); if ((m_header.m_majorVersion != SI_MAJOR_VERSION) || (m_header.m_minorVersion != SI_MINOR_VERSION)) { - sprintf(tempBuffer, "Wrong SI file version. %d.%d expected.", SI_MAJOR_VERSION, SI_MINOR_VERSION); + snprintf(tempBuffer, sizeof(tempBuffer), "Wrong SI file version. %d.%d expected.", SI_MAJOR_VERSION, SI_MINOR_VERSION); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "LEGO® Island Error", tempBuffer, NULL); return FAILURE; } diff --git a/LEGO1/viewmanager/viewlodlist.cpp b/LEGO1/viewmanager/viewlodlist.cpp index ca57bc01..7f442968 100644 --- a/LEGO1/viewmanager/viewlodlist.cpp +++ b/LEGO1/viewmanager/viewlodlist.cpp @@ -84,7 +84,7 @@ ViewLODList* ViewLODListManager::Create(const ROIName& rROIName, int lodCount) list->Release(); char num[12]; - sprintf(num, "%d", g_ROINameUID); + snprintf(num, sizeof(num), "%d", g_ROINameUID); pROIName = new char[strlen(rROIName) + strlen(num) + 1]; strcpy(pROIName, rROIName); strcat(pROIName, num);