Added pointer checks to Android's resource stream.

This fixes issues #1056.
This commit is contained in:
Michał Marszałek 2016-02-08 18:09:59 +01:00 committed by Lukas Dürrenberger
parent 61526628d1
commit 36bb3c4531

View File

@ -49,35 +49,66 @@ m_file (NULL)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
ResourceStream::~ResourceStream() ResourceStream::~ResourceStream()
{ {
AAsset_close(m_file); if (m_file)
{
AAsset_close(m_file);
}
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Int64 ResourceStream::read(void *data, Int64 size) Int64 ResourceStream::read(void *data, Int64 size)
{ {
return AAsset_read(m_file, data, size); if (m_file)
{
return AAsset_read(m_file, data, size);
}
else
{
return -1;
}
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Int64 ResourceStream::seek(Int64 position) Int64 ResourceStream::seek(Int64 position)
{ {
return AAsset_seek(m_file, position, SEEK_SET); if (m_file)
{
return AAsset_seek(m_file, position, SEEK_SET);
}
else
{
return -1;
}
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Int64 ResourceStream::tell() Int64 ResourceStream::tell()
{ {
return getSize() - AAsset_getRemainingLength(m_file); if (m_file)
{
return getSize() - AAsset_getRemainingLength(m_file);
}
else
{
return -1;
}
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Int64 ResourceStream::getSize() Int64 ResourceStream::getSize()
{ {
return AAsset_getLength(m_file); if (m_file)
{
return AAsset_getLength(m_file);
}
else
{
return -1;
}
} }