From f2689c4887e6bd66af34de81cd793322f1dd57c4 Mon Sep 17 00:00:00 2001 From: tycho Date: Tue, 19 May 2015 11:50:59 +0100 Subject: Fixed a lot of warnings --- src/OSSupport/File.cpp | 26 +++++++++++++++++++------- src/OSSupport/File.h | 6 +++--- 2 files changed, 22 insertions(+), 10 deletions(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index 43105b230..53f7c4afe 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -201,7 +201,7 @@ int cFile::Seek (int iPosition) -int cFile::Tell (void) const +ssize_t cFile::Tell (void) const { ASSERT(IsOpen()); @@ -210,14 +210,14 @@ int cFile::Tell (void) const return -1; } - return (int)ftell(m_File); + return ftell(m_File); } -int cFile::GetSize(void) const +ssize_t cFile::GetSize(void) const { ASSERT(IsOpen()); @@ -226,7 +226,7 @@ int cFile::GetSize(void) const return -1; } - int CurPos = Tell(); + ssize_t CurPos = Tell(); if (CurPos < 0) { return -1; @@ -235,7 +235,7 @@ int cFile::GetSize(void) const { return -1; } - int res = Tell(); + ssize_t res = Tell(); if (fseek(m_File, (long)CurPos, SEEK_SET) != 0) { return -1; @@ -256,7 +256,19 @@ int cFile::ReadRestOfFile(AString & a_Contents) return -1; } - size_t DataSize = GetSize() - Tell(); + ssize_t TotalSize = GetSize(); + if (TotalSize < 0) + { + return -1; + } + + ssize_t Position = Tell(); + if (Position < 0) + { + return -1; + } + + auto DataSize = static_cast(TotalSize - Position); // HACK: This depends on the internal knowledge that AString's data() function returns the internal buffer directly a_Contents.assign(DataSize, '\0'); @@ -349,7 +361,7 @@ bool cFile::IsFile(const AString & a_Path) -int cFile::GetSize(const AString & a_FileName) +ssize_t cFile::GetSize(const AString & a_FileName) { struct stat st; if (stat(a_FileName.c_str(), &st) == 0) diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h index 1b5e71a17..e92da4354 100644 --- a/src/OSSupport/File.h +++ b/src/OSSupport/File.h @@ -90,10 +90,10 @@ public: int Seek (int iPosition); /** Returns the current position (bytes from file start) or -1 for failure; asserts if not open */ - int Tell (void) const; + ssize_t Tell (void) const; /** Returns the size of file, in bytes, or -1 for failure; asserts if not open */ - int GetSize(void) const; + ssize_t GetSize(void) const; /** Reads the file from current position till EOF into an AString; returns the number of bytes read or -1 for error */ int ReadRestOfFile(AString & a_Contents); @@ -119,7 +119,7 @@ public: static bool IsFile(const AString & a_Path); /** Returns the size of the file, or a negative number on error */ - static int GetSize(const AString & a_FileName); + static ssize_t GetSize(const AString & a_FileName); /** Creates a new folder with the specified name. Returns true if successful. Path may be relative or absolute */ static bool CreateFolder(const AString & a_FolderPath); -- cgit v1.2.3 From 6cccd2aabbb02fbdc59d55aefd6fd0010f901140 Mon Sep 17 00:00:00 2001 From: tycho Date: Tue, 19 May 2015 13:33:34 +0100 Subject: Properly fix cFile Warnings --- src/OSSupport/File.cpp | 14 +++++++------- src/OSSupport/File.h | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index 53f7c4afe..ed0dda681 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -180,7 +180,7 @@ int cFile::Write(const void * iBuffer, size_t iNumBytes) -int cFile::Seek (int iPosition) +long cFile::Seek (int iPosition) { ASSERT(IsOpen()); @@ -193,7 +193,7 @@ int cFile::Seek (int iPosition) { return -1; } - return (int)ftell(m_File); + return ftell(m_File); } @@ -201,7 +201,7 @@ int cFile::Seek (int iPosition) -ssize_t cFile::Tell (void) const +long cFile::Tell (void) const { ASSERT(IsOpen()); @@ -217,7 +217,7 @@ ssize_t cFile::Tell (void) const -ssize_t cFile::GetSize(void) const +long cFile::GetSize(void) const { ASSERT(IsOpen()); @@ -226,7 +226,7 @@ ssize_t cFile::GetSize(void) const return -1; } - ssize_t CurPos = Tell(); + long CurPos = Tell(); if (CurPos < 0) { return -1; @@ -235,7 +235,7 @@ ssize_t cFile::GetSize(void) const { return -1; } - ssize_t res = Tell(); + long res = Tell(); if (fseek(m_File, (long)CurPos, SEEK_SET) != 0) { return -1; @@ -361,7 +361,7 @@ bool cFile::IsFile(const AString & a_Path) -ssize_t cFile::GetSize(const AString & a_FileName) +long cFile::GetSize(const AString & a_FileName) { struct stat st; if (stat(a_FileName.c_str(), &st) == 0) diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h index e92da4354..6281d1494 100644 --- a/src/OSSupport/File.h +++ b/src/OSSupport/File.h @@ -87,13 +87,13 @@ public: int Write(const void * iBuffer, size_t iNumBytes); /** Seeks to iPosition bytes from file start, returns old position or -1 for failure; asserts if not open */ - int Seek (int iPosition); + long Seek (int iPosition); /** Returns the current position (bytes from file start) or -1 for failure; asserts if not open */ - ssize_t Tell (void) const; + long Tell (void) const; /** Returns the size of file, in bytes, or -1 for failure; asserts if not open */ - ssize_t GetSize(void) const; + long GetSize(void) const; /** Reads the file from current position till EOF into an AString; returns the number of bytes read or -1 for error */ int ReadRestOfFile(AString & a_Contents); @@ -119,7 +119,7 @@ public: static bool IsFile(const AString & a_Path); /** Returns the size of the file, or a negative number on error */ - static ssize_t GetSize(const AString & a_FileName); + static long GetSize(const AString & a_FileName); /** Creates a new folder with the specified name. Returns true if successful. Path may be relative or absolute */ static bool CreateFolder(const AString & a_FolderPath); -- cgit v1.2.3 From 050a014106a57bcdcda6401090da201db15d7b87 Mon Sep 17 00:00:00 2001 From: tycho Date: Tue, 19 May 2015 14:02:02 +0100 Subject: Finish fixing windows --- src/OSSupport/File.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index ed0dda681..6327b3505 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -256,13 +256,13 @@ int cFile::ReadRestOfFile(AString & a_Contents) return -1; } - ssize_t TotalSize = GetSize(); + long TotalSize = GetSize(); if (TotalSize < 0) { return -1; } - ssize_t Position = Tell(); + long Position = Tell(); if (Position < 0) { return -1; -- cgit v1.2.3 From a5624debcb15f5edadeb598d86b4b8ee738d03bd Mon Sep 17 00:00:00 2001 From: tycho Date: Sat, 23 May 2015 12:59:41 +0100 Subject: Fix tests --- src/OSSupport/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/OSSupport') diff --git a/src/OSSupport/CMakeLists.txt b/src/OSSupport/CMakeLists.txt index 0d3c9a63e..981c4c5b0 100644 --- a/src/OSSupport/CMakeLists.txt +++ b/src/OSSupport/CMakeLists.txt @@ -41,6 +41,10 @@ SET (HDRS UDPEndpointImpl.h ) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + add_flags_cxx("-Wno-error=global-constructors") +endif() + if(NOT MSVC) add_library(OSSupport ${SRCS} ${HDRS}) -- cgit v1.2.3 From dae9e5792a4f030ae9e748548a16a89790fbd311 Mon Sep 17 00:00:00 2001 From: tycho Date: Sun, 24 May 2015 12:56:56 +0100 Subject: Made -Weverything an error. --- src/OSSupport/CMakeLists.txt | 2 +- src/OSSupport/GZipFile.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/CMakeLists.txt b/src/OSSupport/CMakeLists.txt index 981c4c5b0..d1db0373d 100644 --- a/src/OSSupport/CMakeLists.txt +++ b/src/OSSupport/CMakeLists.txt @@ -42,7 +42,7 @@ SET (HDRS ) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=global-constructors") + add_flags_cxx("-Wno-error=global-constructors -Wno-error=old-style-cast") endif() if(NOT MSVC) diff --git a/src/OSSupport/GZipFile.h b/src/OSSupport/GZipFile.h index dfb4e8c31..286c98aff 100644 --- a/src/OSSupport/GZipFile.h +++ b/src/OSSupport/GZipFile.h @@ -37,7 +37,7 @@ public: int ReadRestOfFile(AString & a_Contents); /// Writes a_Contents into file, compressing it along the way. Returns true if successful. Multiple writes are supported. - bool Write(const AString & a_Contents) { return Write(a_Contents.data(), (int)(a_Contents.size())); } + bool Write(const AString & a_Contents) { return Write(a_Contents.data(), static_cast(a_Contents.size())); } bool Write(const char * a_Data, int a_Size); -- cgit v1.2.3 From 5049fd0fbf2fe2e54d86d9d0f704d5daa301f819 Mon Sep 17 00:00:00 2001 From: linnemannr Date: Sun, 24 May 2015 20:07:31 -0600 Subject: Support building on FreeBSD SetFlags.cmake Add -lexecinfo to linker flags for FreeBSD to resolve backtrace() lib/sqlite/CMakeLists.txt Define _XOPEN_SOURCE to 600 instead of __POSIX_VISIBLE to 200112 for POSIX 1-2001 support. For POSIX standards, the _XOPEN_SOURCE define controls the eventual value of __POSIX_VISIBLE. _XOPEN_SOURCE is defined to 500 in sqlite.c if not already defined, which sets up _POSIX_C_SOURCE and __POSIX_VISIBLE to the 199506 for POSIX.1c lib/tolua++/CMakeLists.txt src/CMakeLists.txt Add /usr/local/lib to the library search path for FreeBSD builds src/OSSupport/Errors.cpp Correct the strerror_r() implementation determination to check whether _GNU_SOURCE is defined, not what it evaluates to --- src/OSSupport/Errors.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/Errors.cpp b/src/OSSupport/Errors.cpp index a5361e1a6..407799495 100644 --- a/src/OSSupport/Errors.cpp +++ b/src/OSSupport/Errors.cpp @@ -22,7 +22,7 @@ AString GetOSErrorString( int a_ErrNo) // According to http://linux.die.net/man/3/strerror_r there are two versions of strerror_r(): - #if !defined(__APPLE__) && ( _GNU_SOURCE) && !defined(ANDROID_NDK) // GNU version of strerror_r() + #if !defined(__APPLE__) && defined( _GNU_SOURCE) && !defined(ANDROID_NDK) // GNU version of strerror_r() char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer)); if (res != nullptr) -- cgit v1.2.3 From ee34e7131a5a7a308fe431c44741d68a10bb2625 Mon Sep 17 00:00:00 2001 From: linnemannr Date: Sat, 30 May 2015 02:23:57 -0600 Subject: Fix FreeBSD/clang errors caused by -Werror With FreeBSD/clang, -Werror combined with the configured warning flags yields some fatal errors, specifically related to signed conversion, 64 to 32 bit conversion, and tautological compares. CONTRIBUTORS Add myself to the contributor list src/Generating/FinishGen.cpp In cFinishGenPassiveMobs::GetRandomMob(), change the type of RandMob from size_t to the difference_type of the ListOfSpawnables iterator MobIter. Using size_t triggers a 64 bit to 32 bit conversion if the difference_type of the iterator class is 64 bit Also explicitly cast the noise expression to unsigned long so we don't get a signed conversion warning from the modulo against ListOfSpawnables.size() src/OSSupport/StackTrace.cpp FreeBSD 10 and above includes a non glibc implementation of benchmark() for which size_t, not int, is the return type. To account for this and prevent a signed conversion warning, abstract the type for numItems with a macro btsize src/StringUtils.h In StringToInteger(), correct a tautological compare warning for unsigned types with the template. If T is unsigned, comparing std::numeric_limits::min() to the unsigned result is always false. That control can enter this branch in an evaluated template with an unsigned type T may also permit a signed number to be parsed and erroneously stripped of its signedness at runtime. To guard against this and avoid the warning in the case that the number parsed from the string is non-positive, return false and don't try to parse if T is unsigned and control enters the non-positive branch --- src/OSSupport/StackTrace.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/StackTrace.cpp b/src/OSSupport/StackTrace.cpp index 015a53ba0..1ec10f20e 100644 --- a/src/OSSupport/StackTrace.cpp +++ b/src/OSSupport/StackTrace.cpp @@ -12,6 +12,13 @@ #include #endif +// FreeBSD uses size_t for the return type of backtrace() +#if defined(__FreeBSD__) && (__FreeBSD__ >= 10) + #define btsize size_t +#else + #define btsize int +#endif + @@ -34,7 +41,7 @@ void PrintStackTrace(void) // Use the backtrace() function to get and output the stackTrace: // Code adapted from http://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes void * stackTrace[30]; - int numItems = backtrace(stackTrace, ARRAYCOUNT(stackTrace)); + btsize numItems = backtrace(stackTrace, ARRAYCOUNT(stackTrace)); backtrace_symbols_fd(stackTrace, numItems, STDERR_FILENO); #endif } -- cgit v1.2.3