From dd9bb892cb977b9c7767c646cacb64d7b8f80dc3 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 6 Nov 2015 12:18:44 -0500 Subject: [PATCH] [Common] MaxFileSize: Use size_t for memory sizes. --- Source/Common/Log Class.h | 12 ++++++------ Source/Common/Trace.cpp | 13 +++++-------- Source/Common/Trace.h | 2 +- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Source/Common/Log Class.h b/Source/Common/Log Class.h index 69d322cb1..1b155da5d 100644 --- a/Source/Common/Log Class.h +++ b/Source/Common/Log Class.h @@ -15,8 +15,8 @@ class CLog bool m_FlushOnWrite; stdstr m_FileName; bool m_TruncateFileLog; - uint32_t m_MaxFileSize; - uint32_t m_FileChangeSize; + size_t m_MaxFileSize; + size_t m_FileChangeSize; public: CLog ( void ); @@ -29,10 +29,10 @@ public: bool Empty ( void ); void Close ( void ); - inline void SetMaxFileSize ( uint32_t Size ) - { - m_MaxFileSize = Size; - m_FileChangeSize = (uint32_t)(Size * 0.1); + inline void SetMaxFileSize(size_t Size) + { + m_MaxFileSize = Size; + m_FileChangeSize = (size_t)(Size * 0.1); } inline void SetTruncateFile( bool Truncate ) { m_TruncateFileLog = Truncate; } inline void SetFlush ( bool Always ) { m_FlushOnWrite = Always; } diff --git a/Source/Common/Trace.cpp b/Source/Common/Trace.cpp index 313d660f2..e74519fe8 100644 --- a/Source/Common/Trace.cpp +++ b/Source/Common/Trace.cpp @@ -191,7 +191,7 @@ m_FlushFile(FlushFile) m_hLogFile.Open(FileName, Log_Append); } -CTraceFileLog::CTraceFileLog(LPCTSTR FileName, bool FlushFile, LOG_OPEN_MODE eMode, uint32_t dwMaxFileSize) : +CTraceFileLog::CTraceFileLog(LPCTSTR FileName, bool FlushFile, LOG_OPEN_MODE eMode, size_t dwMaxFileSize) : m_FlushFile(FlushFile) { enum { MB = 1024 * 1024 }; @@ -199,14 +199,11 @@ m_FlushFile(FlushFile) m_hLogFile.SetFlush(false); m_hLogFile.SetTruncateFile(true); - if (dwMaxFileSize < 2048 && dwMaxFileSize > 2) - { - m_hLogFile.SetMaxFileSize(dwMaxFileSize * MB); - } - else - { - m_hLogFile.SetMaxFileSize(5 * MB); + if (dwMaxFileSize < 3 || dwMaxFileSize > 2047) + { /* Clamp file size to 5 MB if it exceeds 2047 or falls short of 3. */ + dwMaxFileSize = 5; } + m_hLogFile.SetMaxFileSize(dwMaxFileSize * MB); m_hLogFile.Open(FileName, eMode); } diff --git a/Source/Common/Trace.h b/Source/Common/Trace.h index d3b170633..2e8e2f0cd 100644 --- a/Source/Common/Trace.h +++ b/Source/Common/Trace.h @@ -26,7 +26,7 @@ class CTraceFileLog : public CTraceModule public: CTraceFileLog (const char * FileName, bool FlushFile = true); - CTraceFileLog (const char * FileName, bool FlushFile, LOG_OPEN_MODE eMode, uint32_t dwMaxFileSize = 5); + CTraceFileLog(const char * FileName, bool FlushFile, LOG_OPEN_MODE eMode, size_t dwMaxFileSize = 5); virtual ~CTraceFileLog (); void Write ( const char * Message, bool EndOfLine );