Render the top-level --help "Tools:" block from the registry tools/list * serves. The list used to be hand-maintained in the help text and drifted * when check_index_coverage was added (#1361); deriving it here makes that * divergence impossible. Heap-allocated; caller frees. */ Append at out[len] and return the bytes ACTUALLY written. * * snprintf returns the length it WOULD have written, so
| 1162 | * changing the wrap rule would turn it into an overflow with nothing to notice. |
| 1163 | * Clamping makes `len <= cap - 1` a local invariant no later edit can void. */ |
| 1164 | static size_t help_append(char *out, size_t cap, size_t len, const char *fmt, ...) { |
| 1165 | if (len + 1 >= cap) { |
| 1166 | return 0; |
| 1167 | } |
| 1168 | va_list args; |
| 1169 | va_start(args, fmt); |
| 1170 | int written = vsnprintf(out + len, cap - len, fmt, args); |
| 1171 | va_end(args); |
| 1172 | if (written <= 0) { |
| 1173 | return 0; |
| 1174 | } |
| 1175 | size_t room = cap - len - 1; |
| 1176 | return (size_t)written > room ? room : (size_t)written; |
| 1177 | } |
| 1178 | |
| 1179 | char *cbm_mcp_tools_help_list(void) { |
| 1180 | size_t cap = SLEN("Tools:") + 2; /* trailing newline + NUL */ |
no outgoing calls
no test coverage detected