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 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/OSSupport/File.cpp') 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) -- 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 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/OSSupport/File.cpp') 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) -- 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/File.cpp') 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