| 1266 | //============================================================= |
| 1267 | template <class T> |
| 1268 | int AudioFile<T>::getIndexOfChunk (const std::vector<uint8_t>& source, const std::string& chunkHeaderID, int startIndex, Endianness endianness) |
| 1269 | { |
| 1270 | constexpr int dataLen = 4; |
| 1271 | |
| 1272 | if (chunkHeaderID.size() != dataLen) |
| 1273 | { |
| 1274 | assert (false && "Invalid chunk header ID string"); |
| 1275 | return -1; |
| 1276 | } |
| 1277 | |
| 1278 | int i = startIndex; |
| 1279 | while (i < source.size() - dataLen) |
| 1280 | { |
| 1281 | if (memcmp (&source[i], chunkHeaderID.data(), dataLen) == 0) |
| 1282 | { |
| 1283 | return i; |
| 1284 | } |
| 1285 | |
| 1286 | i += dataLen; |
| 1287 | |
| 1288 | // If somehow we don't have 4 bytes left to read, then exit with -1 |
| 1289 | if ((i + 4) >= source.size()) |
| 1290 | return -1; |
| 1291 | |
| 1292 | int32_t chunkSize = fourBytesToInt (source, i, endianness); |
| 1293 | // Assume chunk size is invalid if it's greater than the number of bytes remaining in source |
| 1294 | if (chunkSize > (source.size() - i - dataLen) || (chunkSize < 0)) |
| 1295 | { |
| 1296 | assert (false && "Invalid chunk size"); |
| 1297 | return -1; |
| 1298 | } |
| 1299 | i += (dataLen + chunkSize); |
| 1300 | } |
| 1301 | |
| 1302 | return -1; |
| 1303 | } |
| 1304 | |
| 1305 | //============================================================= |
| 1306 | template <class T> |
nothing calls this directly
no outgoing calls
no test coverage detected