🚚 Fix crash when trying to read beyond last disk file
This commit is contained in:
parent
b884e87972
commit
736e92ebd5
3 changed files with 5 additions and 4 deletions
|
@ -33,7 +33,7 @@ void initFileReader(char path[], unsigned long offset) {
|
|||
|
||||
|
||||
//Reads the given amount of bytes from the file and writes them into the given buffer. Automatically opens next file if EOF is reached.
|
||||
void getBytes(uint8_t* buffer, unsigned long numBytes) {
|
||||
void getBytes(uint8_t* buffer, unsigned long numBytes, bool isLast) {
|
||||
uint8_t* bufferPosition = buffer;
|
||||
unsigned long remainingBytes = numBytes;
|
||||
|
||||
|
@ -52,7 +52,8 @@ void getBytes(uint8_t* buffer, unsigned long numBytes) {
|
|||
remainingBytes -= availableBytes;
|
||||
|
||||
//If we've reached end of file, close file and open next file
|
||||
if (file.offset == file.size) {
|
||||
//Unless we've reached the end, in that case don't open next file in case we've reached the end of the last disk
|
||||
if (!isLast && file.offset == file.size) {
|
||||
openNextFile();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
|
||||
void initFileReader(char path[], unsigned long offset);
|
||||
|
||||
void getBytes(uint8_t* buffer, unsigned long numBytes);
|
||||
void getBytes(uint8_t* buffer, unsigned long numBytes, bool isLast);
|
||||
|
|
|
@ -95,7 +95,7 @@ int main(int argc, char *argv[]) {
|
|||
while (remainingBytes > 0 || !hasReachedEnd) {
|
||||
if (needToRead) {
|
||||
chunkSize = min(BUFFER_SIZE - uncompressedPosition, remainingBytes);
|
||||
getBytes(compressedChunk, chunkSize);
|
||||
getBytes(compressedChunk, chunkSize, chunkSize == remainingBytes);
|
||||
remainingBytes -= chunkSize;
|
||||
|
||||
//Decrypt file if it is encrypted
|
||||
|
|
Loading…
Reference in a new issue