mirror of https://github.com/libAthena/athena.git
Fix sign bug
Prevent blockSize from exceeding file's length
This commit is contained in:
parent
a7c180db00
commit
8d3524b1f6
|
@ -12,7 +12,7 @@ namespace io
|
||||||
class FileReader : public IStreamReader
|
class FileReader : public IStreamReader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileReader(const std::string& filename, atUint32 cacheSize = (32 * 1024));
|
FileReader(const std::string& filename, atInt32 cacheSize = (32 * 1024));
|
||||||
virtual ~FileReader();
|
virtual ~FileReader();
|
||||||
inline const std::string& filename() const
|
inline const std::string& filename() const
|
||||||
{return m_filename;}
|
{return m_filename;}
|
||||||
|
@ -27,12 +27,12 @@ public:
|
||||||
atUint64 length() const;
|
atUint64 length() const;
|
||||||
atUint64 readUBytesToBuf(void* buf, atUint64 len);
|
atUint64 readUBytesToBuf(void* buf, atUint64 len);
|
||||||
|
|
||||||
void setCacheSize(const atUint32 blockSize);
|
void setCacheSize(const atInt32 blockSize);
|
||||||
protected:
|
protected:
|
||||||
std::string m_filename;
|
std::string m_filename;
|
||||||
FILE* m_fileHandle;
|
FILE* m_fileHandle;
|
||||||
std::unique_ptr<atUint8[]> m_cacheData;
|
std::unique_ptr<atUint8[]> m_cacheData;
|
||||||
atUint32 m_blockSize;
|
atInt32 m_blockSize;
|
||||||
atInt32 m_curBlock;
|
atInt32 m_curBlock;
|
||||||
atUint64 m_offset;
|
atUint64 m_offset;
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace Athena
|
||||||
{
|
{
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
||||||
FileReader::FileReader(const std::string& filename, atUint32 cacheSize)
|
FileReader::FileReader(const std::string& filename, atInt32 cacheSize)
|
||||||
: m_filename(filename),
|
: m_filename(filename),
|
||||||
m_fileHandle(nullptr),
|
m_fileHandle(nullptr),
|
||||||
m_cacheData(nullptr),
|
m_cacheData(nullptr),
|
||||||
|
@ -145,9 +145,13 @@ atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileReader::setCacheSize(const atUint32 blockSize)
|
void FileReader::setCacheSize(const atInt32 blockSize)
|
||||||
{
|
{
|
||||||
m_blockSize = blockSize;
|
m_blockSize = blockSize;
|
||||||
|
|
||||||
|
if (m_blockSize > length())
|
||||||
|
m_blockSize = length();
|
||||||
|
|
||||||
m_curBlock = -1;
|
m_curBlock = -1;
|
||||||
if (m_blockSize > 0)
|
if (m_blockSize > 0)
|
||||||
m_cacheData.reset(new atUint8[m_blockSize]);
|
m_cacheData.reset(new atUint8[m_blockSize]);
|
||||||
|
|
Loading…
Reference in New Issue