| 545 | } sh_str_t; |
| 546 | |
| 547 | static void sh_str_add(CBMArena *a, sh_str_t *b, const char *p, size_t n) { |
| 548 | if (b->bad || !p) { |
| 549 | b->bad = true; |
| 550 | return; |
| 551 | } |
| 552 | if (b->len + n + SKIP_ONE > b->cap) { |
| 553 | size_t ncap = (b->cap ? b->cap : SH_GROW_MIN) * PAIR_LEN; |
| 554 | while (ncap < b->len + n + SKIP_ONE) { |
| 555 | ncap *= PAIR_LEN; |
| 556 | } |
| 557 | char *nb = cbm_arena_alloc(a, ncap); |
| 558 | if (!nb) { |
| 559 | b->bad = true; |
| 560 | return; |
| 561 | } |
| 562 | if (b->len) { |
| 563 | memcpy(nb, b->buf, b->len); |
| 564 | } |
| 565 | b->buf = nb; |
| 566 | b->cap = ncap; |
| 567 | } |
| 568 | memcpy(b->buf + b->len, p, n); |
| 569 | b->len += n; |
| 570 | b->buf[b->len] = '\0'; |
| 571 | } |
| 572 | |
| 573 | static const char *sh_str_done(sh_str_t *b) { |
| 574 | if (b->bad) { |
no test coverage detected