Added support for calling throwException() from InputIterator and added a check for negative string sizes.
This commit is contained in:
@@ -8,6 +8,9 @@
|
||||
namespace osgDB
|
||||
{
|
||||
|
||||
// forward declare
|
||||
class InputStream;
|
||||
|
||||
class OSGDB_EXPORT OutputIterator : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
@@ -64,12 +67,16 @@ protected:
|
||||
class OSGDB_EXPORT InputIterator : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
InputIterator() : _in(0), _failed(false) {}
|
||||
InputIterator() : _in(0), _inputStream(0), _failed(false) {}
|
||||
virtual ~InputIterator() {}
|
||||
|
||||
void setStream( std::istream* istream ) { _in = istream; }
|
||||
std::istream* getStream() { return _in; }
|
||||
const std::istream* getStream() const { return _in; }
|
||||
|
||||
void setInputStream( InputStream* inputStream) { _inputStream = inputStream; }
|
||||
InputStream* getInputStream() { return _inputStream; }
|
||||
const InputStream* getInputStream() const { return _inputStream; }
|
||||
|
||||
void checkStream() const { if (_in->rdstate()&_in->failbit) _failed = true; }
|
||||
bool isFailed() const { return _failed; }
|
||||
@@ -100,9 +107,12 @@ public:
|
||||
|
||||
virtual bool matchString( const std::string& /*str*/ ) { return false; }
|
||||
virtual void advanceToCurrentEndBracket() {}
|
||||
|
||||
|
||||
void throwException( const std::string& msg );
|
||||
|
||||
protected:
|
||||
std::istream* _in;
|
||||
std::istream* _in;
|
||||
osgDB::InputStream* _inputStream;
|
||||
mutable bool _failed;
|
||||
};
|
||||
|
||||
|
||||
@@ -692,6 +692,8 @@ InputStream::ReadType InputStream::start( InputIterator* inIterator )
|
||||
if ( !_in )
|
||||
throwException( "InputStream: Null stream specified." );
|
||||
if ( getException() ) return type;
|
||||
|
||||
_in->setInputStream(this);
|
||||
|
||||
// Check OSG header information
|
||||
unsigned int version = 0;
|
||||
|
||||
@@ -145,11 +145,15 @@ public:
|
||||
virtual void readString( std::string& s )
|
||||
{
|
||||
int size = 0; readInt( size );
|
||||
if ( size )
|
||||
if ( size>0 )
|
||||
{
|
||||
s.resize( size );
|
||||
_in->read( (char*)s.c_str(), size );
|
||||
}
|
||||
else if ( size<0 )
|
||||
{
|
||||
throwException( "InputStream::readString() error, negative string size read." );
|
||||
}
|
||||
}
|
||||
|
||||
virtual void readStream( std::istream& (*fn)(std::istream&) ) {}
|
||||
|
||||
Reference in New Issue
Block a user