x64: some code clean up and remove warning on Common and 3rd party

This commit is contained in:
zilmar 2022-07-11 19:30:25 +09:30
parent 8726931be5
commit de5a8460fd
14 changed files with 63 additions and 61 deletions

View File

@ -61,7 +61,7 @@
<PreprocessSuppressLineNumbers>false</PreprocessSuppressLineNumbers>
<PreprocessKeepComments>false</PreprocessKeepComments>
<StringPooling>true</StringPooling>
<MinimalRebuild>true</MinimalRebuild>
<MinimalRebuild>false</MinimalRebuild>
<ExceptionHandling>Async</ExceptionHandling>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<StructMemberAlignment>Default</StructMemberAlignment>

View File

@ -36,6 +36,7 @@
<PrecompiledHeader />
<WarningLevel>Level4</WarningLevel>
<AdditionalIncludeDirectories>$(SolutionDir)\Source\3rdParty\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4267;4310</DisableSpecificWarnings>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>

View File

@ -45,9 +45,6 @@
<ClCompile Include="pngset.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="pngtest.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="pngtrans.c">
<Filter>Source Files</Filter>
</ClCompile>

View File

@ -35,7 +35,7 @@
<ClCompile>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DisableSpecificWarnings>4005;4006;4100;4127;4131;4189;4244;4701;4703;4996</DisableSpecificWarnings>
<DisableSpecificWarnings>4005;4006;4100;4127;4131;4189;4244;4701;4703;4996;4267;4067</DisableSpecificWarnings>
<!-- Fix for later VC versions on XP: 45KB + 436 -->
<PreprocessorDefinitions>Z_BUFSIZE=46516;$(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>

View File

@ -18,17 +18,17 @@
CFile::CFile() :
#ifdef USE_WINDOWS_API
m_hFile(INVALID_HANDLE_VALUE),
m_hFile(INVALID_HANDLE_VALUE),
#else
m_hFile(nullptr),
m_hFile(nullptr),
#endif
m_bCloseOnDelete(false)
m_bCloseOnDelete(false)
{
}
CFile::CFile(void * hFile) :
m_hFile(hFile),
m_bCloseOnDelete(true)
m_hFile(hFile),
m_bCloseOnDelete(true)
{
if (hFile == 0)
{
@ -38,11 +38,11 @@ m_bCloseOnDelete(true)
CFile::CFile(const char * lpszFileName, uint32_t nOpenFlags) :
#ifdef USE_WINDOWS_API
m_hFile(INVALID_HANDLE_VALUE),
m_hFile(INVALID_HANDLE_VALUE),
#else
m_hFile(nullptr),
m_hFile(nullptr),
#endif
m_bCloseOnDelete(true)
m_bCloseOnDelete(true)
{
Open(lpszFileName, nOpenFlags);
}

View File

@ -19,11 +19,11 @@ public:
modeNoTruncate = 0x2000,
};
enum SeekPosition
{
begin = 0x0,
current = 0x1,
end = 0x2
enum SeekPosition
{
begin = 0x0,
current = 0x1,
end = 0x2
};
virtual bool Open(const char * lpszFileName, uint32_t nOpenFlags ) = 0;
@ -44,28 +44,18 @@ public:
class CFile : public CFileBase
{
// Attributes
void * m_hFile;
bool m_bCloseOnDelete;
public:
// Flag values
// Constructors
CFile();
CFile(void * hFile);
CFile(const char * lpszFileName, uint32_t nOpenFlags);
// Deconstructors
virtual ~CFile();
// Operations
virtual bool Open(const char * lpszFileName, uint32_t nOpenFlags );
uint32_t SeekToEnd ( void );
void SeekToBegin ( void );
uint32_t SeekToEnd ( void );
void SeekToBegin ( void );
// Overridable
virtual uint32_t GetPosition() const;
virtual int32_t Seek(int32_t lOff, SeekPosition nFrom);
virtual bool SetLength(uint32_t dwNewLen);
@ -82,4 +72,7 @@ public:
private:
CFile(const CFile&);
CFile& operator=(const CFile&);
void * m_hFile;
bool m_bCloseOnDelete;
};

View File

@ -1,4 +1,5 @@
#include "IniFile.h"
#include "StdString.h"
#include <stdlib.h>
#include <stdarg.h>
@ -29,7 +30,7 @@ void CIniFileBase::fInsertSpaces(int Pos, int NoOfSpaces)
long end, WritePos;
m_File.Seek(0, CFileBase::end);
end = m_File.GetPosition();
end = (long)m_File.GetPosition();
if (NoOfSpaces > 0)
{
@ -42,7 +43,7 @@ void CIniFileBase::fInsertSpaces(int Pos, int NoOfSpaces)
if (SizeToRead > 0)
{
m_File.Seek(SizeToRead * -1, CFileBase::current);
WritePos = m_File.GetPosition();
WritePos = (long)m_File.GetPosition();
memset(Data, 0, sizeof(Data));
result = m_File.Read(Data, SizeToRead);
m_File.Seek(WritePos, CFileBase::begin);
@ -151,7 +152,7 @@ int CIniFileBase::GetStringFromFile(char * & String, std::unique_ptr<char> &Data
void CIniFileBase::SaveCurrentSection(void)
{
if (!m_CurrentSectionDirty)
if (!m_CurrentSectionDirty || m_ReadOnly)
{
return;
}
@ -179,7 +180,7 @@ void CIniFileBase::SaveCurrentSection(void)
sprintf(SectionName.get(), "%s[%s]%s", m_LineFeed, m_CurrentSection.c_str(), m_LineFeed);
}
m_File.Write(SectionName.get(), (int)strlen(SectionName.get()));
m_CurrentSectionFilePos = m_File.GetPosition();
m_CurrentSectionFilePos = (long)m_File.GetPosition();
m_SectionsPos.insert(FILELOC::value_type(m_CurrentSection, m_CurrentSectionFilePos));
}
else
@ -219,7 +220,7 @@ void CIniFileBase::SaveCurrentSection(void)
if (result <= 1) { continue; }
if (strlen(CleanLine(Input)) <= 1 || Input[0] != '[')
{
EndPos = ((m_File.GetPosition() - DataSize) + ReadPos);
EndPos = (long)((m_File.GetPosition() - DataSize) + ReadPos);
continue;
}
@ -342,7 +343,7 @@ bool CIniFileBase::MoveToSectionNameData(const char * lpSectionName, bool Change
// Take off the ']' from the end of the string
CurrentSection[lineEndPos] = 0;
CurrentSection += 1;
m_lastSectionSearch = (m_File.GetPosition() - DataSize) + ReadPos;
m_lastSectionSearch = (long)((m_File.GetPosition() - DataSize) + ReadPos);
m_SectionsPos.insert(FILELOC::value_type(CurrentSection, m_lastSectionSearch));
if (_stricmp(lpSectionName, CurrentSection) != 0)
@ -492,6 +493,11 @@ bool CIniFileBase::IsFileOpen(void)
return m_File.IsOpen();
}
bool CIniFileBase::IsReadOnly(void)
{
return m_ReadOnly;
}
bool CIniFileBase::DeleteSection(const char * lpSectionName)
{
CGuard Guard(m_CS);
@ -504,7 +510,7 @@ bool CIniFileBase::DeleteSection(const char * lpSectionName)
return false;
}
m_File.Seek(m_CurrentSectionFilePos, CFileBase::begin);
long DeleteSectionStart = m_CurrentSectionFilePos - (strlen(lpSectionName) + strlen(m_LineFeed) + 2);
long DeleteSectionStart = (long)(m_CurrentSectionFilePos - (strlen(lpSectionName) + strlen(m_LineFeed) + 2));
long NextSectionStart = -1;
{
@ -519,10 +525,10 @@ bool CIniFileBase::DeleteSection(const char * lpSectionName)
if (Input[0] != '[')
{
NextLine = (m_File.GetPosition() - DataSize) + ReadPos;
NextLine = (int)((m_File.GetPosition() - DataSize) + ReadPos);
continue;
}
NextSectionStart = NextLine != 0 ? NextLine : (m_File.GetPosition() - DataSize) + ReadPos;
NextSectionStart = NextLine != 0 ? NextLine : (long)((m_File.GetPosition() - DataSize) + ReadPos);
break;
} while (result >= 0);
}
@ -530,7 +536,7 @@ bool CIniFileBase::DeleteSection(const char * lpSectionName)
if (NextSectionStart != -1)
{
m_File.Seek(0, CFileBase::end);
long end = m_File.GetPosition();
long end = (long)m_File.GetPosition();
long ReadPos = NextSectionStart;
long WritePos = DeleteSectionStart;
@ -655,8 +661,12 @@ bool CIniFileBase::GetNumber(const char * lpSectionName, const char * lpKeyName,
return false;
}
void CIniFileBase::SaveString(const char * lpSectionName, const char * lpKeyName, const char * lpString)
void CIniFileBase::SaveString(const char * lpSectionName, const char * lpKeyName, const char * lpString)
{
if (m_ReadOnly)
{
return;
}
CGuard Guard(m_CS);
if (!m_File.IsOpen())
{
@ -719,8 +729,12 @@ void CIniFileBase::SaveString(const char * lpSectionName, const char * lpKeyNam
}
}
void CIniFileBase::SaveNumber(const char * lpSectionName, const char * lpKeyName, int32_t Value)
void CIniFileBase::SaveNumber(const char * lpSectionName, const char * lpKeyName, uint32_t Value)
{
if (m_ReadOnly)
{
return;
}
// Translate the string to an ASCII version and save as text
SaveString(lpSectionName, lpKeyName, FormatStr("%d", Value).c_str());
}
@ -806,7 +820,7 @@ void CIniFileBase::GetKeyValueData(const char * lpSectionName, KeyValueData & Li
if (!MoveToSectionNameData(strSection.c_str(), false)) { return; }
int MaxDataSize = 0, DataSize = 0, ReadPos = 0, result;
std::unique_ptr <char> Data;
std::unique_ptr<char> Data;
char *Input = nullptr;
do
{
@ -818,7 +832,7 @@ void CIniFileBase::GetKeyValueData(const char * lpSectionName, KeyValueData & Li
if (Pos == nullptr) { continue; }
Pos[0] = 0;
List.insert(KeyValueData::value_type(Input, &Pos[1]));
List.insert(KeyValueData::value_type(stdstr(Input).Trim(), &Pos[1]));
} while (result >= 0);
}

View File

@ -29,6 +29,7 @@ public:
bool IsEmpty();
bool IsFileOpen(void);
bool IsReadOnly(void);
bool DeleteSection(const char * lpSectionName);
bool GetString(const char * lpSectionName, const char * lpKeyName, const char * lpDefault, std::string & Value);
std::string GetString(const char * lpSectionName, const char * lpKeyName, const char * lpDefault);
@ -37,7 +38,7 @@ public:
bool GetNumber(const char * lpSectionName, const char * lpKeyName, uint32_t nDefault, uint32_t & Value);
virtual void SaveString(const char * lpSectionName, const char * lpKeyName, const char * lpString);
virtual void SaveNumber(const char * lpSectionName, const char * lpKeyName, int32_t Value);
virtual void SaveNumber(const char * lpSectionName, const char * lpKeyName, uint32_t Value);
void SetAutoFlush(bool AutoFlush);
void FlushChanges(void);
bool EntryExists(const char * lpSectionName, const char * lpKeyName);
@ -67,7 +68,7 @@ private:
}
};
typedef std::map<std::string, long> FILELOC;
typedef std::map<std::string, long, insensitive_compare> FILELOC;
typedef FILELOC::iterator FILELOC_ITR;
typedef std::map<std::string, std::string, insensitive_compare> KeyValueList;
@ -91,7 +92,6 @@ private:
bool MoveToSectionNameData(const char * lpSectionName, bool ChangeCurrentSection);
const char * CleanLine(char * Line);
void ClearSectionPosList(long FilePos);
};
template <class CFileStorage>

View File

@ -39,7 +39,7 @@ bool CLog::Open( const char * FileName, LOG_OPEN_MODE mode /* = Log_New */)
}
m_FileName = (const char *)File;
m_hLogFile.Seek(0,mode == Log_Append ? CFile::end : CFile::begin);
m_FileSize = mode == Log_Append ? m_hLogFile.GetLength() : 0;
m_FileSize = mode == Log_Append ? (uint32_t)m_hLogFile.GetLength() : 0;
return true;
}
@ -94,17 +94,17 @@ void CLog::Log( const char * Message )
if (m_TruncateFileLog && m_FileSize > m_MaxFileSize)
{
// Check file size
m_FileSize = m_hLogFile.GetLength();
m_FileSize = (uint32_t)m_hLogFile.GetLength();
// If larger then maximum size then
if (m_FileSize > m_MaxFileSize)
{
if (!m_FlushOnWrite)
{
m_hLogFile.Flush();
m_FileSize = m_hLogFile.GetLength();
m_FileSize = (uint32_t)m_hLogFile.GetLength();
}
uint32_t end = m_hLogFile.SeekToEnd();
uint32_t end = (uint32_t)m_hLogFile.SeekToEnd();
// Move to reduce size
m_hLogFile.Seek((end - m_MaxFileSize) + m_FileChangeSize,CFile::begin);
@ -162,7 +162,7 @@ void CLog::Log( const char * Message )
// Clean up
m_hLogFile.SetEndOfFile();
m_hLogFile.Flush();
m_FileSize = m_hLogFile.GetLength();
m_FileSize = (uint32_t)m_hLogFile.GetLength();
} // end if
}
}

View File

@ -27,10 +27,7 @@ uint32_t CRandom::next()
void CRandom::set_state(uint32_t state_value)
{
if (state_value == 0)
m_state = 1;
else
m_state = state_value;
m_state = state_value == 0 ? 1 : state_value;
}
uint32_t CRandom::get_state()

View File

@ -90,13 +90,13 @@ void stdstr::Format(const char * strFormat, ...)
stdstr& stdstr::ToLower(void)
{
std::transform(begin(), end(), begin(), (int(*)(int)) tolower);
std::transform(begin(), end(), begin(), (char(*)(int)) tolower);
return *this;
}
stdstr& stdstr::ToUpper(void)
{
std::transform(begin(), end(), begin(), (int(*)(int)) toupper);
std::transform(begin(), end(), begin(), (char(*)(int)) toupper);
return *this;
}

View File

@ -42,7 +42,7 @@ void SyncEvent::Trigger()
#endif
}
bool SyncEvent::IsTriggered(int32_t iWaitTime)
bool SyncEvent::IsTriggered(int32_t iWaitTime) const
{
#ifdef _WIN32
return (WAIT_OBJECT_0 == WaitForSingleObject(m_Event, iWaitTime));

View File

@ -10,7 +10,7 @@ public:
~SyncEvent(void);
void Trigger (void);
bool IsTriggered (int32_t iWaitTime = 0);
bool IsTriggered (int32_t iWaitTime = 0) const;
void Reset();
void * GetHandle();

View File

@ -195,7 +195,7 @@ MD5::MD5(const unsigned char *input, unsigned int input_length)
MD5::MD5(const stdstr & string)
{
init(); // Must be called by all constructors
update((const unsigned char *)string.c_str(), string.length());
update((const unsigned char *)string.c_str(), (uint4)string.length());
finalize();
}