From af8058498e6fa7bcbf13541ca590feb303d6688e Mon Sep 17 00:00:00 2001 From: aramis_acg Date: Sat, 7 May 2011 23:40:36 +0000 Subject: [PATCH] - StreamReader now should be able to deal with files opened in text mode. # rename StreamReader::_Begin() to InternBegin(), underscore+capital letter is reserved in C++. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@988 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/StreamReader.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/code/StreamReader.h b/code/StreamReader.h index 76f92bc6d..16880f92a 100644 --- a/code/StreamReader.h +++ b/code/StreamReader.h @@ -91,7 +91,7 @@ public: , le(le) { ai_assert(stream); - _Begin(); + InternBegin(); } // --------------------------------------------------------------------- @@ -100,7 +100,7 @@ public: , le(le) { ai_assert(stream); - _Begin(); + InternBegin(); } // --------------------------------------------------------------------- @@ -303,8 +303,13 @@ private: } // --------------------------------------------------------------------- - void _Begin() { + void InternBegin() { if (!stream) { + // incase someone wonders: StreamReader is frequently invoked with + // no prior validation whether the input stream is valid. Since + // no one bothers changing the error message, this message here + // is passed down to the caller and 'unable to open file' + // simply describes best what happened. throw DeadlyImportError("StreamReader: Unable to open file"); } @@ -314,8 +319,10 @@ private: } current = buffer = new int8_t[s]; - stream->Read(current,s,1); - end = limit = &buffer[s]; + const size_t read = stream->Read(current,1,s); + // (read < s) can only happen if the stream was opened in text mode, in which case FileSize() is not reliable + ai_assert(read <= s); + end = limit = &buffer[read]; } private: