Skip to content

Commit 8d3524b

Browse files
committed
Fix sign bug
Prevent blockSize from exceeding file's length
1 parent a7c180d commit 8d3524b

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

include/Athena/FileReader.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace io
1212
class FileReader : public IStreamReader
1313
{
1414
public:
15-
FileReader(const std::string& filename, atUint32 cacheSize = (32 * 1024));
15+
FileReader(const std::string& filename, atInt32 cacheSize = (32 * 1024));
1616
virtual ~FileReader();
1717
inline const std::string& filename() const
1818
{return m_filename;}
@@ -27,12 +27,12 @@ class FileReader : public IStreamReader
2727
atUint64 length() const;
2828
atUint64 readUBytesToBuf(void* buf, atUint64 len);
2929

30-
void setCacheSize(const atUint32 blockSize);
30+
void setCacheSize(const atInt32 blockSize);
3131
protected:
3232
std::string m_filename;
3333
FILE* m_fileHandle;
3434
std::unique_ptr<atUint8[]> m_cacheData;
35-
atUint32 m_blockSize;
35+
atInt32 m_blockSize;
3636
atInt32 m_curBlock;
3737
atUint64 m_offset;
3838
};

src/Athena/FileReader.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Athena
1414
{
1515
namespace io
1616
{
17-
FileReader::FileReader(const std::string& filename, atUint32 cacheSize)
17+
FileReader::FileReader(const std::string& filename, atInt32 cacheSize)
1818
: m_filename(filename),
1919
m_fileHandle(nullptr),
2020
m_cacheData(nullptr),
@@ -145,9 +145,13 @@ atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len)
145145
}
146146
}
147147

148-
void FileReader::setCacheSize(const atUint32 blockSize)
148+
void FileReader::setCacheSize(const atInt32 blockSize)
149149
{
150150
m_blockSize = blockSize;
151+
152+
if (m_blockSize > length())
153+
m_blockSize = length();
154+
151155
m_curBlock = -1;
152156
if (m_blockSize > 0)
153157
m_cacheData.reset(new atUint8[m_blockSize]);

0 commit comments

Comments
 (0)