From acb9c9c260a9ee29f4d46f8248eefcac11533dd6 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Mon, 4 Aug 2014 09:49:25 +0400 Subject: [PATCH] Check ftell() result for error code before using it. --- tinyxml2.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 25691b9..a6ad63a 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -1695,9 +1695,14 @@ XMLError XMLDocument::LoadFile( FILE* fp ) } fseek( fp, 0, SEEK_END ); - size_t size = ftell( fp ); + const long filelength = ftell( fp ); fseek( fp, 0, SEEK_SET ); + if ( filelength == -1L ) { + SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); + return _errorID; + } + const size_t size = filelength; if ( size == 0 ) { SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); return _errorID;