From: <rel...@us...> - 2013-03-12 18:49:38
|
Revision: 1566 http://sourceforge.net/p/modplug/code/1566 Author: relabsoluness Date: 2013-03-12 18:49:28 +0000 (Tue, 12 Mar 2013) Log Message: ----------- [Ref] Cleaned up some compiler warnings, fixed faulty definition of nullptr on compilers that supports it and some other minor tweaks. Modified Paths: -------------- trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/common/serialization_utils.cpp trunk/OpenMPT/common/serialization_utils.h trunk/OpenMPT/common/stdafx.h trunk/OpenMPT/common/typedefs.h trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/soundlib/plugins/PluginEventQueue.h trunk/OpenMPT/soundlib/tuning.cpp trunk/OpenMPT/soundlib/tuning.h Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2013-03-12 16:48:18 UTC (rev 1565) +++ trunk/OpenMPT/common/misc_util.h 2013-03-12 18:49:28 UTC (rev 1566) @@ -298,6 +298,18 @@ namespace Util { + // Numeric traits provide compile time values for integer min, max limits. + template <class T> struct NumericTraits {}; + template <> struct NumericTraits<int8> {static const int8 maxValue = int8_max; static const int8 minValue = int8_min;}; + template <> struct NumericTraits<int16> {static const int16 maxValue = int16_max; static const int16 minValue = int16_min;}; + template <> struct NumericTraits<int32> {static const int32 maxValue = int32_max; static const int32 minValue = int32_min;}; + template <> struct NumericTraits<int64> {static const int64 maxValue = int64_max; static const int64 minValue = int64_min;}; + + template <> struct NumericTraits<uint8> {static const uint8 maxValue = uint8_max; static const uint8 minValue = 0;}; + template <> struct NumericTraits<uint16> {static const uint16 maxValue = uint16_max; static const uint16 minValue = 0;}; + template <> struct NumericTraits<uint32> {static const uint32 maxValue = uint32_max; static const uint32 minValue = 0;}; + template <> struct NumericTraits<uint64> {static const uint64 maxValue = uint64_max; static const uint64 minValue = 0;}; + // Like std::max, but avoids conflict with max-macro. template <class T> inline const T& Max(const T& a, const T& b) {return (std::max)(a, b);} Modified: trunk/OpenMPT/common/serialization_utils.cpp =================================================================== --- trunk/OpenMPT/common/serialization_utils.cpp 2013-03-12 16:48:18 UTC (rev 1565) +++ trunk/OpenMPT/common/serialization_utils.cpp 2013-03-12 18:49:28 UTC (rev 1566) @@ -441,7 +441,7 @@ m_Status |= SNW_SUBENTRY_FAILURE; delete m_pSubEntry; m_pSubEntry = nullptr; - WriteMapItem(pId, nIdLength, m_posSubEntryStart - m_posStart, m_pOstrm->tellp() - m_posSubEntryStart, ""); + WriteMapItem(pId, nIdLength, static_cast<RposType>(m_posSubEntryStart - m_posStart), static_cast<DataSize>(m_pOstrm->tellp() - m_posSubEntryStart), ""); IncrementWriteCounter(); } @@ -533,8 +533,8 @@ else if (GetFlag(RwfRMapHasId) == false) // Not ID's in map. { ReadEntry e; - e.rposStart = posReadBegin - m_posStart; - e.nSize = m_pIstrm->tellg() - posReadBegin; + e.rposStart = static_cast<RposType>(posReadBegin - m_posStart); + e.nSize = static_cast<DataSize>(m_pIstrm->tellg() - posReadBegin); AddReadNote(&e, m_nCounter); } else // Entry not found. @@ -551,8 +551,13 @@ void Ssb::OnWroteItem(const void* pId, const size_t nIdSize, const Postype& posBeforeWrite) //----------------------------------------------------------------------------------------- { - RposType nEntrySize = m_pOstrm->tellp() - posBeforeWrite; + const Offtype nRawEntrySize = m_pOstrm->tellp() - posBeforeWrite; + if (nRawEntrySize > DataSize_max) + { AddWriteNote(SNW_INSUFFICIENT_DATASIZETYPE); return; } + + DataSize nEntrySize = static_cast<DataSize>(nRawEntrySize); + if(GetFlag(RwfRMapHasSize) && nEntrySize > (uint64_max >> 2)) { AddWriteNote(SNW_DATASIZETYPE_OVERFLOW); return; } @@ -569,10 +574,10 @@ { AddWriteNote(SNW_INSUFFICIENT_FIXEDSIZE); return; } } if (GetFlag(RwfRwHasMap)) - WriteMapItem(pId, nIdSize, posBeforeWrite - m_posStart, nEntrySize, ""); + WriteMapItem(pId, nIdSize, static_cast<RposType>(posBeforeWrite - m_posStart), nEntrySize, ""); if (m_fpLogFunc != nullptr) - AddWriteNote(pId, nIdSize, m_nCounter, nEntrySize, posBeforeWrite - m_posStart); + AddWriteNote(pId, nIdSize, m_nCounter, nEntrySize, static_cast<RposType>(posBeforeWrite - m_posStart)); IncrementWriteCounter(); } @@ -725,7 +730,13 @@ if(tempU64 > Offtype_max) { AddReadNote(SNR_INSUFFICIENT_STREAM_OFFTYPE); return; } } - m_rposEndofHdrData = iStrm.tellg() - m_posStart; + + const Offtype rawEndOfHdrData = iStrm.tellg() - m_posStart; + + if (rawEndOfHdrData < 0 || rawEndOfHdrData > RposType_max) + { AddReadNote(SNR_INSUFFICIENT_RPOSTYPE); return; } + + m_rposEndofHdrData = static_cast<RposType>(rawEndOfHdrData); m_rposMapBegin = (GetFlag(RwfRwHasMap)) ? static_cast<RposType>(tempU64) : m_rposEndofHdrData; if (GetFlag(RwfRwHasMap) == false) @@ -822,8 +833,9 @@ // startpos. if (GetFlag(RwfRMapHasStartpos) == false && (GetFlag(RwfRMapHasSize) || m_nFixedEntrySize > 0)) { + const RposType offset = static_cast<RposType>(m_posDataBegin - m_posStart); for(size_t i = 0; i < m_nReadEntrycount; i++) - mapData[i].rposStart += (m_posDataBegin - m_posStart); + mapData[i].rposStart += offset; } } Modified: trunk/OpenMPT/common/serialization_utils.h =================================================================== --- trunk/OpenMPT/common/serialization_utils.h 2013-03-12 16:48:18 UTC (rev 1565) +++ trunk/OpenMPT/common/serialization_utils.h 2013-03-12 18:49:28 UTC (rev 1566) @@ -34,16 +34,19 @@ typedef Offtype Postype; typedef std::streamsize Streamsize; -typedef UINT_PTR DataSize; // Data size type. -typedef UINT_PTR RposType; // Relative position type. -typedef UINT_PTR NumType; // Entry count type. -const DataSize DataSize_max = MAXUINT_PTR; -const RposType RposType_max = MAXUINT_PTR; -const NumType NumType_max = MAXUINT_PTR; +//typedef uintptr_t DataSize; // Data size type. +//typedef uintptr_t RposType; // Relative position type. +//typedef uintptr_t NumType; // Entry count type. +typedef uintptr_t DataSize; // Data size type. +typedef uintptr_t RposType; // Relative position type. +typedef uintptr_t NumType; // Entry count type. +const DataSize DataSize_max = Util::NumericTraits<DataSize>::maxValue; +const RposType RposType_max = Util::NumericTraits<RposType>::maxValue; +const NumType NumType_max = Util::NumericTraits<NumType>::maxValue; const DataSize invalidDatasize = DataSize_max; -const Offtype Offtype_min = (std::numeric_limits<Offtype>::min)(); -const Offtype Offtype_max = (std::numeric_limits<Offtype>::max)(); +const Offtype Offtype_min = Util::NumericTraits<Offtype>::minValue; +const Offtype Offtype_max = Util::NumericTraits<Offtype>::maxValue; typedef std::basic_string<TCHAR> String; @@ -66,6 +69,7 @@ SNR_INSUFFICIENT_STREAM_OFFTYPE = 5 | SNT_FAILURE, SNR_OBJECTCLASS_IDMISMATCH = 6 | SNT_FAILURE, SNR_TOO_MANY_ENTRIES_TO_READ = 7 | SNT_FAILURE, + SNR_INSUFFICIENT_RPOSTYPE = 8 | SNT_FAILURE, // Read notes and warnings. SNR_ZEROENTRYCOUNT = 0x80 | SNT_NOTE, // 0x80 == 1 << 7 @@ -79,6 +83,7 @@ SNW_DATASIZETYPE_OVERFLOW = (0x13) | SNT_FAILURE, SNW_MAX_WRITE_COUNT_REACHED = (0x14) | SNT_FAILURE, SNW_SUBENTRY_FAILURE = (0x15) | SNT_FAILURE, + SNW_INSUFFICIENT_DATASIZETYPE = (0x16) | SNT_FAILURE, }; bool IsPrintableId(const void* pvId, const size_t nLength); // Return true if given id is printable, false otherwise. Modified: trunk/OpenMPT/common/stdafx.h =================================================================== --- trunk/OpenMPT/common/stdafx.h 2013-03-12 16:48:18 UTC (rev 1565) +++ trunk/OpenMPT/common/stdafx.h 2013-03-12 18:49:28 UTC (rev 1566) @@ -111,16 +111,6 @@ #pragma warning(error : 4309) // Treat "truncation of constant value"-warning as error. -// Definitions for MSVC versions to write more understandable conditional-compilation, -// e.g. #if (_MSC_VER > MSVC_VER_2008) instead of #if (_MSC_VER > 1500) -#define MSVC_VER_VC71 1310 -#define MSVC_VER_2003 MSVC_VER_VC71 -#define MSVC_VER_VC8 1400 -#define MSVC_VER_2005 MSVC_VER_VC8 -#define MSVC_VER_VC9 1500 -#define MSVC_VER_2008 MSVC_VER_VC9 -#define MSVC_VER_VC10 1600 -#define MSVC_VER_2010 MSVC_VER_VC10 //{{AFX_INSERT_LOCATION}} // Microsoft Developer Studio will insert additional declarations immediately before the previous line. Modified: trunk/OpenMPT/common/typedefs.h =================================================================== --- trunk/OpenMPT/common/typedefs.h 2013-03-12 16:48:18 UTC (rev 1565) +++ trunk/OpenMPT/common/typedefs.h 2013-03-12 18:49:28 UTC (rev 1566) @@ -10,12 +10,23 @@ #pragma once -#ifndef nullptr -#define nullptr 0 +// Definitions for MSVC versions to write more understandable conditional-compilation, +// e.g. #if (_MSC_VER > MSVC_VER_2008) instead of #if (_MSC_VER > 1500) +#define MSVC_VER_VC71 1310 +#define MSVC_VER_2003 MSVC_VER_VC71 +#define MSVC_VER_VC8 1400 +#define MSVC_VER_2005 MSVC_VER_VC8 +#define MSVC_VER_VC9 1500 +#define MSVC_VER_2008 MSVC_VER_VC9 +#define MSVC_VER_VC10 1600 +#define MSVC_VER_2010 MSVC_VER_VC10 + +#if (_MSC_VER < MSVC_VER_2010) + #define nullptr 0 #endif // CountOf macro computes the number of elements in a statically-allocated array. -#if _MSC_VER >= 1400 +#if _MSC_VER >= MSVC_VER_2005 #define CountOf(x) _countof(x) #else #define CountOf(x) (sizeof(x)/sizeof(x[0])) @@ -26,8 +37,9 @@ #define C_ASSERT(expr) typedef char __C_ASSERT__[(expr)?1:-1] #endif #define STATIC_ASSERT(expr) C_ASSERT(expr) -#ifndef static_assert -#define static_assert(expr, msg) C_ASSERT(expr) + +#if (_MSC_VER < MSVC_VER_2010) + #define static_assert(expr, msg) C_ASSERT(expr) #endif typedef __int8 int8; Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2013-03-12 16:48:18 UTC (rev 1565) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2013-03-12 18:49:28 UTC (rev 1566) @@ -251,7 +251,7 @@ void GetPluginInformation(AEffect *effect, VSTPluginLib &library) //--------------------------------------------------------------- { - library.category = static_cast<VSTPluginLib::PluginCategory>(effect->dispatcher(effect, effGetPlugCategory, 0, nullptr, nullptr, 0.0f)); + library.category = static_cast<VSTPluginLib::PluginCategory>(effect->dispatcher(effect, effGetPlugCategory, 0, 0, nullptr, 0.0f)); library.isInstrument = ((effect->flags & effFlagsIsSynth) || !effect->numInputs); if(library.isInstrument) @@ -1593,7 +1593,7 @@ bool CVstPlugin::CanAutomateParameter(PlugParamIndex index) //--------------------------------------------------------- { - return (Dispatch(effCanBeAutomated, index, nullptr, nullptr, 0.0f) != 0); + return (Dispatch(effCanBeAutomated, index, 0, nullptr, 0.0f) != 0); } @@ -1910,7 +1910,7 @@ CString paramName; - if(Dispatch(effGetParameterProperties, param, nullptr, &properties, 0.0f) == 1) + if(Dispatch(effGetParameterProperties, param, 0, &properties, 0.0f) == 1) { StringFixer::SetNullTerminator(properties.label); paramName = properties.label; @@ -2753,7 +2753,7 @@ UINT nLen = nParams * sizeof(float); ULONG nType = *(ULONG *)m_pMixStruct->pPluginData; - if ((Dispatch(effIdentify, 0, nullptr, nullptr, 0) == 'NvEf') && (nType == 'NvEf')) + if ((Dispatch(effIdentify, 0, 0, nullptr, 0) == 'NvEf') && (nType == 'NvEf')) { void *p = nullptr; Dispatch(effGetChunk, 0,0, &p, 0); //init plug for chunk reception @@ -2826,7 +2826,7 @@ { if (m_pEffect) { - return Dispatch(effGetParamName, nIndex, nullptr, pszName, 0.0f); + return Dispatch(effGetParamName, nIndex, 0, pszName, 0.0f); } return 0; } @@ -2845,7 +2845,7 @@ { m_pMixStruct->Info.SetBypass(bypass); - Dispatch(effSetBypass, bypass ? 1 : 0, nullptr, nullptr, 0.0f); + Dispatch(effSetBypass, bypass ? 1 : 0, 0, nullptr, 0.0f); #ifdef MODPLUG_TRACKER if(m_pModDoc) @@ -2913,7 +2913,7 @@ bool CVstPlugin::CanRecieveMidiEvents() //------------------------------------- { - return (CVstPlugin::Dispatch(effCanDo, 0, nullptr, "receiveVstMidiEvent", 0.0f) != 0); + return (CVstPlugin::Dispatch(effCanDo, 0, 0, "receiveVstMidiEvent", 0.0f) != 0); } Modified: trunk/OpenMPT/soundlib/plugins/PluginEventQueue.h =================================================================== --- trunk/OpenMPT/soundlib/plugins/PluginEventQueue.h 2013-03-12 16:48:18 UTC (rev 1565) +++ trunk/OpenMPT/soundlib/plugins/PluginEventQueue.h 2013-03-12 18:49:28 UTC (rev 1566) @@ -59,7 +59,7 @@ PluginEventQueue() { numEvents = 0; - reserved = nullptr; + reserved = 0; MemsetZero(events); MemsetZero(criticalSection); InitializeCriticalSection(&criticalSection); Modified: trunk/OpenMPT/soundlib/tuning.cpp =================================================================== --- trunk/OpenMPT/soundlib/tuning.cpp 2013-03-12 16:48:18 UTC (rev 1565) +++ trunk/OpenMPT/soundlib/tuning.cpp 2013-03-12 18:49:28 UTC (rev 1566) @@ -458,96 +458,6 @@ } -CTuningRTI* CTuningRTI::DeserializeOLD(istream& inStrm) -//----------------------------------------------------------- -{ - if(!inStrm.good()) - return 0; - - char begin[8]; - char end[8]; - int16 version; - - const long startPos = inStrm.tellg(); - - //First checking is there expected begin sequence. - inStrm.read(reinterpret_cast<char*>(&begin), sizeof(begin)); - if(memcmp(begin, "CTRTI_B.", 8)) - { - //Returning stream position if beginmarker was not found. - inStrm.seekg(startPos); - return 0; - } - - //Version - inStrm.read(reinterpret_cast<char*>(&version), sizeof(version)); - if(version != 3) - return 0; - - CTuningRTI* pT = new CTuningRTI; - - //Baseclass deserialization - if(pT->CTuning::DeserializeOLD(inStrm) == SERIALIZATION_FAILURE) - { - delete pT; - return 0; - } - - //Ratiotable - if(VectorFromBinaryStream<RATIOTYPE, uint16>(inStrm, pT->m_RatioTable)) - { - delete pT; - return 0; - } - - //Fineratios - if(VectorFromBinaryStream<RATIOTYPE, uint16>(inStrm, pT->m_RatioTableFine)) - { - delete pT; - return 0; - } - else - pT->m_FineStepCount = pT->m_RatioTableFine.size(); - - //m_StepMin - inStrm.read(reinterpret_cast<char*>(&pT->m_StepMin), sizeof(pT->m_StepMin)); - if (pT->m_StepMin < -200 || pT->m_StepMin > 200) - { - delete pT; - return nullptr; - } - - //m_GroupSize - inStrm.read(reinterpret_cast<char*>(&pT->m_GroupSize), sizeof(pT->m_GroupSize)); - if(pT->m_GroupSize < 0) - { - delete pT; - return 0; - } - - //m_GroupRatio - inStrm.read(reinterpret_cast<char*>(&pT->m_GroupRatio), sizeof(pT->m_GroupRatio)); - if(pT->m_GroupRatio < 0) - { - delete pT; - return 0; - } - - if(pT->GetFineStepCount() > 0) pT->ProSetFineStepCount(pT->GetFineStepCount() - 1); - - inStrm.read(reinterpret_cast<char*>(&end), sizeof(end)); - if(memcmp(end, "CTRTI_E.", 8)) - { - delete pT; - return 0; - } - - - return pT; -} - - - CTUNINGBASE::SERIALIZATION_RETURN_TYPE CTuningRTI::Serialize(ostream& outStrm) const //---------------------------------------------------------------------------------- { Modified: trunk/OpenMPT/soundlib/tuning.h =================================================================== --- trunk/OpenMPT/soundlib/tuning.h 2013-03-12 16:48:18 UTC (rev 1565) +++ trunk/OpenMPT/soundlib/tuning.h 2013-03-12 18:49:28 UTC (rev 1566) @@ -67,8 +67,8 @@ static uint32 GetVersion() {return s_SerializationVersion;} - //Try to read old version (v.3) and return pointer to new instance if succesfull, else 0. - static CTuningRTI* DeserializeOLD(istream& iStrm); + //Try to read old version (v.3) and return pointer to new instance if succesfull, else nullptr. + static CTuningRTI* DeserializeOLD(istream&) {return 0;} SERIALIZATION_RETURN_TYPE Serialize(ostream& out) const; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |