| 369 | } |
| 370 | |
| 371 | static bool json_append_string(char *buf, int buf_size, int *off, const char *name, |
| 372 | const char *value, bool comma) { |
| 373 | int needed = json_escaped_len(value ? value : ""); |
| 374 | char *escaped = malloc((size_t)needed + 1); |
| 375 | if (!escaped) { |
| 376 | return false; |
| 377 | } |
| 378 | int actual = cbm_json_escape(escaped, needed + 1, value ? value : ""); |
| 379 | bool ok = actual == needed && append_fmt_checked(buf, buf_size, off, "\"%s\":\"%s\"%s", name, |
| 380 | escaped, comma ? "," : ""); |
| 381 | free(escaped); |
| 382 | return ok; |
| 383 | } |
| 384 | |
| 385 | int cbm_git_context_props_json(const cbm_git_context_t *ctx, char *buf, int buf_size) { |
| 386 | if (!ctx || !buf || buf_size <= 0) { |
no test coverage detected