🚚 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.
|
//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;
|
uint8_t* bufferPosition = buffer;
|
||||||
unsigned long remainingBytes = numBytes;
|
unsigned long remainingBytes = numBytes;
|
||||||
|
|
||||||
|
@ -52,7 +52,8 @@ void getBytes(uint8_t* buffer, unsigned long numBytes) {
|
||||||
remainingBytes -= availableBytes;
|
remainingBytes -= availableBytes;
|
||||||
|
|
||||||
//If we've reached end of file, close file and open next file
|
//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();
|
openNextFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,4 +4,4 @@
|
||||||
|
|
||||||
void initFileReader(char path[], unsigned long offset);
|
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) {
|
while (remainingBytes > 0 || !hasReachedEnd) {
|
||||||
if (needToRead) {
|
if (needToRead) {
|
||||||
chunkSize = min(BUFFER_SIZE - uncompressedPosition, remainingBytes);
|
chunkSize = min(BUFFER_SIZE - uncompressedPosition, remainingBytes);
|
||||||
getBytes(compressedChunk, chunkSize);
|
getBytes(compressedChunk, chunkSize, chunkSize == remainingBytes);
|
||||||
remainingBytes -= chunkSize;
|
remainingBytes -= chunkSize;
|
||||||
|
|
||||||
//Decrypt file if it is encrypted
|
//Decrypt file if it is encrypted
|
||||||
|
|
Loading…
Reference in a new issue