Skip to content

Commit 74d37d1

Browse files
committed
Use fixed memory for chapters (dynamic caused crashes)
1 parent b0cf4db commit 74d37d1

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

BoxTonies.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ bool BoxTonies::loadTonieByPath(uint8_t* path) {
7171
cursor += readBytes;
7272
header.audioChapterCount++;
7373
}
74-
free(header.audioChapters);
75-
header.audioChapters = new uint32_t[header.audioChapterCount];
7674
cursor = blockStart; //reread
7775
for (uint8_t i = 0; i < header.audioChapterCount; i++) {
7876
uint32_t chapter = (uint32_t)readVariant(&buffer[cursor], bufferLen-cursor, readBytes);
@@ -120,8 +118,11 @@ void BoxTonies::clearHeader() {
120118
//header.hash = {0}; //TODO
121119
header.audioLength = 0;
122120
header.audioId = 0;
123-
free(header.audioChapters);
124121
header.audioChapterCount = 0;
122+
for (uint8_t i=0; i<99; i++) {
123+
header.audioChapters[i] = 0;
124+
}
125+
125126
}
126127

127128
uint64_t BoxTonies::readVariant(uint8_t* buffer, uint16_t length, uint8_t& readBytes) {

BoxTonies.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class BoxTonies {
1616
uint8_t hash[20];
1717
uint32_t audioLength; //length in bytes
1818
uint32_t audioId; //id, which is the unix time stamp of file creation
19-
uint32_t* audioChapters; //Ogg page numbers for Chapters
19+
uint32_t audioChapters[99]; //Ogg page numbers for Chapters
2020
uint8_t audioChapterCount;
2121
};
2222

0 commit comments

Comments
 (0)