Format one call arg as JSON. Returns snprintf result. */
| 2146 | |
| 2147 | /* Format one call arg as JSON. Returns snprintf result. */ |
| 2148 | static int format_call_arg(char *buf, size_t bufsize, const CBMCallArg *a, const char *expr) { |
| 2149 | char esc_k[CBM_SZ_128]; |
| 2150 | char esc_e[CBM_SZ_128]; |
| 2151 | char esc_v[CBM_SZ_128]; |
| 2152 | cbm_json_escape(esc_e, sizeof(esc_e), expr); |
| 2153 | if (a->keyword && a->value) { |
| 2154 | cbm_json_escape(esc_k, sizeof(esc_k), a->keyword); |
| 2155 | cbm_json_escape(esc_v, sizeof(esc_v), a->value); |
| 2156 | return snprintf(buf, bufsize, "{\"i\":%d,\"k\":\"%s\",\"e\":\"%s\",\"v\":\"%s\"}", a->index, |
| 2157 | esc_k, esc_e, esc_v); |
| 2158 | } |
| 2159 | if (a->keyword) { |
| 2160 | cbm_json_escape(esc_k, sizeof(esc_k), a->keyword); |
| 2161 | return snprintf(buf, bufsize, "{\"i\":%d,\"k\":\"%s\",\"e\":\"%s\"}", a->index, esc_k, |
| 2162 | esc_e); |
| 2163 | } |
| 2164 | if (a->value) { |
| 2165 | cbm_json_escape(esc_v, sizeof(esc_v), a->value); |
| 2166 | return snprintf(buf, bufsize, "{\"i\":%d,\"e\":\"%s\",\"v\":\"%s\"}", a->index, esc_e, |
| 2167 | esc_v); |
| 2168 | } |
| 2169 | return snprintf(buf, bufsize, "{\"i\":%d,\"e\":\"%s\"}", a->index, esc_e); |
| 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) { |
no test coverage detected