The entry for num; created (zeroed) when absent. *fresh says which. */
| 1561 | |
| 1562 | /* The entry for num; created (zeroed) when absent. *fresh says which. */ |
| 1563 | static pdf_xent_t *xref_slot(pdf_doc_t *d, pdf_xref_t *x, int64_t num, bool *fresh) { |
| 1564 | int64_t i = pdf_map_get(&x->by_num, (uint64_t)num); |
| 1565 | if (i >= 0) { |
| 1566 | *fresh = false; |
| 1567 | return &x->v[i]; |
| 1568 | } |
| 1569 | if (x->n == x->cap) { |
| 1570 | int ncap = x->cap ? x->cap * 2 : PDF_MAP_MIN; |
| 1571 | pdf_xent_t *g = |
| 1572 | (pdf_xent_t *)cbm_realloc(CBM_MEM_CLASS_EXTRACT, x->v, (size_t)ncap * sizeof(*g)); |
| 1573 | if (!g) { |
| 1574 | d->nomem = true; |
| 1575 | return NULL; |
| 1576 | } |
| 1577 | x->v = g; |
| 1578 | x->cap = ncap; |
| 1579 | } |
| 1580 | if (!pdf_map_put(&x->by_num, (uint64_t)num, x->n)) { |
| 1581 | d->nomem = true; |
| 1582 | return NULL; |
| 1583 | } |
| 1584 | pdf_xent_t *e = &x->v[x->n++]; |
| 1585 | memset(e, 0, sizeof(*e)); |
| 1586 | e->num = num; |
| 1587 | *fresh = true; |
| 1588 | return e; |
| 1589 | } |
| 1590 | |
| 1591 | /* "[ws]*(\d{1,10})[ws]+(\d{1,5})[ws]*([nf])" at p. */ |
| 1592 | static bool match_xref_entry(const pdf_doc_t *d, size_t p, int64_t *off, int64_t *gen, char *kind, |
no test coverage detected