"(" leading whole entries ")" ... "# )" within CBM_CALLABLE_SIG_MAX. */
| 899 | |
| 900 | /* "(" leading whole entries ")" ... "#<hash>)" within CBM_CALLABLE_SIG_MAX. */ |
| 901 | static const char *sig_capped(CBMArena *a, const sig_ctx_t *c, const char *full, size_t n) { |
| 902 | char tail[SIG_CAPPED_TAIL + 1]; |
| 903 | snprintf(tail, sizeof(tail), "#%016llx)", (unsigned long long)sig_fnv64(full, n)); |
| 904 | size_t keep = 0; /* bytes of entry text after the "(" */ |
| 905 | bool comma = sig_writes_types(c); |
| 906 | int limit = c->too_many ? SIG_MAX_ENTRIES : c->entries; |
| 907 | for (int i = 0; i < limit; i++) { |
| 908 | size_t end = c->entry_end[i]; |
| 909 | if (end < c->open_off + 1 || end > c->close_off) { |
| 910 | break; |
| 911 | } |
| 912 | size_t candidate = end - (c->open_off + 1); |
| 913 | if (1 + candidate + (comma ? 1 : 0) + SIG_CAPPED_TAIL > CBM_CALLABLE_SIG_MAX) { |
| 914 | break; |
| 915 | } |
| 916 | keep = candidate; |
| 917 | } |
| 918 | char *out = cbm_arena_alloc(a, CBM_CALLABLE_SIG_MAX + 1); |
| 919 | if (!out) { |
| 920 | return NULL; |
| 921 | } |
| 922 | size_t len = 0; |
| 923 | out[len++] = '('; |
| 924 | memcpy(out + len, c->buf + c->open_off + 1, keep); |
| 925 | len += keep; |
| 926 | if (keep && comma) { |
| 927 | out[len++] = ','; |
| 928 | } |
| 929 | memcpy(out + len, tail, SIG_CAPPED_TAIL); |
| 930 | len += SIG_CAPPED_TAIL; |
| 931 | out[len] = '\0'; |
| 932 | return out; |
| 933 | } |
| 934 | |
| 935 | /* ── Builder ───────────────────────────────────────────────────── */ |
| 936 |
no test coverage detected