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