| 99 | } |
| 100 | |
| 101 | bool pdf_scratch(pdf_doc_t *d, size_t need) { |
| 102 | if (need <= d->scratch_cap) { |
| 103 | return true; |
| 104 | } |
| 105 | size_t ncap = d->scratch_cap ? d->scratch_cap : PDF_SCRATCH_MIN; |
| 106 | while (ncap < need) { |
| 107 | if (ncap > SIZE_MAX / 2) { |
| 108 | ncap = need; |
| 109 | break; |
| 110 | } |
| 111 | ncap *= 2; |
| 112 | } |
| 113 | unsigned char *g = (unsigned char *)cbm_realloc(CBM_MEM_CLASS_EXTRACT, d->scratch, ncap); |
| 114 | if (!g) { |
| 115 | d->nomem = true; |
| 116 | return false; |
| 117 | } |
| 118 | d->scratch = g; |
| 119 | d->scratch_cap = ncap; |
| 120 | return true; |
| 121 | } |
| 122 | |
| 123 | /* A growable byte buffer from the memory core (decoder output). */ |
| 124 | typedef struct { |
no test coverage detected