| 468 | } |
| 469 | |
| 470 | char *findNthAtom(uint32_t atomTypeIn, int index, const uint8_t *xsb, int xsbSize, int *atomSizeOut) |
| 471 | { |
| 472 | const uint8_t *atom = xsb, *xsbEnd = xsb + xsbSize; |
| 473 | |
| 474 | if (0 == index) { // hack - only validate XS_A header at root... |
| 475 | if (c_read32be(xsb + 4) != FOURCC('X', 'S', '_', 'A')) |
| 476 | return NULL; |
| 477 | |
| 478 | atom += 8; |
| 479 | } |
| 480 | |
| 481 | while (atom < xsbEnd) { |
| 482 | int32_t atomSize = c_read32be(atom); |
| 483 | uint32_t atomType = c_read32be(atom + 4); |
| 484 | |
| 485 | if ((atomSize < 8) || ((atom + atomSize) > xsbEnd)) |
| 486 | return NULL; |
| 487 | |
| 488 | if (atomType == atomTypeIn) { |
| 489 | index -= 1; |
| 490 | if (index <= 0) { |
| 491 | if (atomSizeOut) |
| 492 | *atomSizeOut = atomSize - 8; |
| 493 | return (char *)(atom + 8); |
| 494 | } |
| 495 | } |
| 496 | atom += atomSize; |
| 497 | } |
| 498 | |
| 499 | if (atomSizeOut) |
| 500 | *atomSizeOut = 0; |
| 501 | |
| 502 | return NULL; |
| 503 | } |
| 504 | |
| 505 | #endif |
| 506 |
no outgoing calls
no test coverage detected