Skip to content

Commit

Permalink
Use fixed memory for chapters (dynamic caused crashes)
Browse files Browse the repository at this point in the history
  • Loading branch information
SciLor committed Jul 20, 2021
1 parent b0cf4db commit 74d37d1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions BoxTonies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ bool BoxTonies::loadTonieByPath(uint8_t* path) {
cursor += readBytes;
header.audioChapterCount++;
}
free(header.audioChapters);
header.audioChapters = new uint32_t[header.audioChapterCount];
cursor = blockStart; //reread
for (uint8_t i = 0; i < header.audioChapterCount; i++) {
uint32_t chapter = (uint32_t)readVariant(&buffer[cursor], bufferLen-cursor, readBytes);
Expand Down Expand Up @@ -120,8 +118,11 @@ void BoxTonies::clearHeader() {
//header.hash = {0}; //TODO
header.audioLength = 0;
header.audioId = 0;
free(header.audioChapters);
header.audioChapterCount = 0;
for (uint8_t i=0; i<99; i++) {
header.audioChapters[i] = 0;
}

}

uint64_t BoxTonies::readVariant(uint8_t* buffer, uint16_t length, uint8_t& readBytes) {
Expand Down
2 changes: 1 addition & 1 deletion BoxTonies.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class BoxTonies {
uint8_t hash[20];
uint32_t audioLength; //length in bytes
uint32_t audioId; //id, which is the unix time stamp of file creation
uint32_t* audioChapters; //Ogg page numbers for Chapters
uint32_t audioChapters[99]; //Ogg page numbers for Chapters
uint8_t audioChapterCount;
};

Expand Down

0 comments on commit 74d37d1

Please sign in to comment.