| 2170 | } |
| 2171 | |
| 2172 | static size_t append_args_json(char *buf, size_t bufsize, size_t pos, const CBMCall *call) { |
| 2173 | if (call->arg_count == 0 || pos >= bufsize - PP_ARGS_MARGIN) { |
| 2174 | return pos; |
| 2175 | } |
| 2176 | int n = snprintf(buf + pos, bufsize - pos, ",\"args\":["); |
| 2177 | if (n <= 0) { |
| 2178 | return pos; |
| 2179 | } |
| 2180 | pos += (size_t)n; |
| 2181 | for (int i = 0; i < call->arg_count && pos < bufsize - CBM_ARG_JSON_GUARD; i++) { |
| 2182 | const CBMCallArg *a = &call->args[i]; |
| 2183 | size_t mark = pos; /* rollback point (before the separator) */ |
| 2184 | if (i > 0 && pos < bufsize - SKIP_ONE) { |
| 2185 | buf[pos++] = ','; |
| 2186 | } |
| 2187 | char expr_buf[CBM_SZ_128]; |
| 2188 | sanitize_expr(expr_buf, a->expr); |
| 2189 | n = format_call_arg(buf + pos, bufsize - pos, a, expr_buf); |
| 2190 | /* snprintf returns the UNtruncated length: if the arg did not fully |
| 2191 | * fit, advancing pos by n would push it past buf and the buf[pos] |
| 2192 | * writes below would overflow. Drop the arg whole (atomic field — |
| 2193 | * keeps the array valid) and stop appending. */ |
| 2194 | if (n <= 0 || (size_t)n >= bufsize - pos) { |
| 2195 | pos = mark; |
| 2196 | break; |
| 2197 | } |
| 2198 | pos += (size_t)n; |
| 2199 | } |
| 2200 | if (pos < bufsize - SKIP_ONE) { |
| 2201 | buf[pos++] = ']'; |
| 2202 | } |
| 2203 | buf[pos] = '\0'; |
| 2204 | return pos; |
| 2205 | } |
| 2206 | |
| 2207 | /* Scan call args for a URL-like route path and handler reference. */ |
| 2208 | static bool is_path_keyword(const char *keyword) { |
no test coverage detected