From 4ecdb004e81a459ea63ebd7127e1c945df43f9ce Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 17 Jul 2017 18:55:36 +0300 Subject: Fix issues detected by coverity. --- src/fs/virtfs/fsdir.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/fs/virtfs/fsdir.cpp') diff --git a/src/fs/virtfs/fsdir.cpp b/src/fs/virtfs/fsdir.cpp index 60fc9f977..be980ae65 100644 --- a/src/fs/virtfs/fsdir.cpp +++ b/src/fs/virtfs/fsdir.cpp @@ -377,6 +377,11 @@ namespace FsDir } #ifdef USE_FILE_FOPEN const long pos = ftell(fd); + if (pos < 0) + { + reportAlways("FsDir::fileLength ftell error."); + return -1; + } fseek(fd, 0, SEEK_END); const long sz = ftell(fd); fseek(fd, pos, SEEK_SET); @@ -483,6 +488,13 @@ namespace FsDir #ifdef USE_FILE_FOPEN fseek(fd, 0, SEEK_END); const long sz = ftell(fd); + if (sz < 0) + { + reportAlways("FsDir::fileLength ftell error."); + if (fd != FILEHDEFAULT) + FILECLOSE(fd); + return nullptr; + } fseek(fd, 0, SEEK_SET); fileSize = static_cast(sz); #else // USE_FILE_FOPEN -- cgit v1.2.3-70-g09d2