From f17020106860c388f2489c8a5fb18410ec38c039 Mon Sep 17 00:00:00 2001 From: Silent Date: Sun, 9 Apr 2017 18:13:52 +0200 Subject: [PATCH] safer ini reading --- SilentPatchSA/SilentPatchSA.cpp | 20 +++++++++++++------- SilentPatchSA/VehicleSA.cpp | 6 +++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 259138f..918ee06 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -1064,7 +1064,7 @@ void DrawScriptSpritesAndRectangles( uint8_t arg ) orgDrawScriptSpritesAndRectangles( arg ); } -std::vector< std::pair > doubleRearWheelsList; +std::vector< std::pair > doubleRearWheelsList; void ReadDoubleRearWheels(const wchar_t* pPath) { const size_t SCRATCH_PAD_SIZE = 32767; @@ -1073,17 +1073,23 @@ void ReadDoubleRearWheels(const wchar_t* pPath) GetPrivateProfileSectionW( L"DoubleRearWheels", reader.GetBuffer(), reader.GetSize(), pPath ); while ( const wchar_t* str = reader.GetString() ) { - wchar_t textLine[32]; + wchar_t textLine[64]; wchar_t* context = nullptr; wchar_t* token; wcscpy_s( textLine, str ); token = wcstok_s( textLine, L"=", &context ); - - int toList = _wtoi( token ); - if ( toList != 0 ) + + uint32_t toList = wcstoul( token, nullptr, 0 ); + if ( toList == 0 ) continue; + + wchar_t* begin = wcstok_s( nullptr, L"=", &context ); + if ( begin == nullptr ) continue; + + wchar_t* end = nullptr; + bool value = wcstoul( begin, &end, 0 ) != 0; + if ( begin != end ) { - bool value = _wtoi( wcstok_s( nullptr, L"=", &context ) ) != 0; doubleRearWheelsList.emplace_back( toList, value ); } } @@ -1097,7 +1103,7 @@ bool __stdcall CheckDoubleRWheelsList( void* modelInfo, uint8_t* handlingData ) if ( modelInfo == lastModelInfo ) return lastResult; lastModelInfo = modelInfo; - ptrdiff_t modelID = std::distance( ms_modelInfoPtrs, std::find( ms_modelInfoPtrs, ms_modelInfoPtrs+m_numModelInfoPtrs, modelInfo ) ); + uint32_t modelID = std::distance( ms_modelInfoPtrs, std::find( ms_modelInfoPtrs, ms_modelInfoPtrs+m_numModelInfoPtrs, modelInfo ) ); auto it = std::find_if( doubleRearWheelsList.begin(), doubleRearWheelsList.end(), [modelID]( const auto& item ) { return item.first == modelID; diff --git a/SilentPatchSA/VehicleSA.cpp b/SilentPatchSA/VehicleSA.cpp index c2353a9..9f0b268 100644 --- a/SilentPatchSA/VehicleSA.cpp +++ b/SilentPatchSA/VehicleSA.cpp @@ -7,9 +7,9 @@ #include "TimerSA.h" #include "DelimStringReader.h" -std::vector vecRotorExceptions; +std::vector vecRotorExceptions; -static bool ShouldIgnoreRotor( unsigned int id ) +static bool ShouldIgnoreRotor( uint32_t id ) { return std::find( vecRotorExceptions.begin(), vecRotorExceptions.end(), id ) != vecRotorExceptions.end(); } @@ -78,7 +78,7 @@ void ReadRotorFixExceptions(const wchar_t* pPath) GetPrivateProfileSectionW( L"RotorFixExceptions", reader.GetBuffer(), reader.GetSize(), pPath ); while ( const wchar_t* str = reader.GetString() ) { - unsigned int toList = _wtoi( str ); + uint32_t toList = wcstoul( str, nullptr, 0 ); if ( toList != 0 ) vecRotorExceptions.push_back( toList ); }