| 624 | } |
| 625 | |
| 626 | static cbm_userconfig_snapshot_status_t snapshot_parse(CBMArena *arena, cbm_userconfig_t *cfg) { |
| 627 | cbm_userconfig_source_t *source = cfg->project_source; |
| 628 | yyjson_read_err error = {0}; |
| 629 | yyjson_doc *doc = yyjson_read_opts((char *)source->bytes, source->len, 0, NULL, &error); |
| 630 | if (!doc) |
| 631 | return error.code == YYJSON_READ_ERROR_MEMORY_ALLOCATION ? CBM_USERCONFIG_SNAPSHOT_OOM |
| 632 | : CBM_USERCONFIG_SNAPSHOT_INVALID; |
| 633 | yyjson_val *extra = NULL; |
| 634 | cbm_userconfig_snapshot_status_t status = snapshot_extensions(yyjson_doc_get_root(doc), &extra); |
| 635 | size_t count = extra ? yyjson_obj_size(extra) : 0; |
| 636 | /* The 64 KiB source cap already bounds count; keep allocation math explicit. */ |
| 637 | if (count > MAX_CONFIG_SIZE || count > SIZE_MAX / sizeof(*cfg->entries)) |
| 638 | status = CBM_USERCONFIG_SNAPSHOT_LIMIT; |
| 639 | if (status == CBM_USERCONFIG_SNAPSHOT_OK && count > 0) { |
| 640 | cfg->entries = cbm_arena_calloc(arena, count * sizeof(*cfg->entries)); |
| 641 | if (!cfg->entries) |
| 642 | status = CBM_USERCONFIG_SNAPSHOT_OOM; |
| 643 | } |
| 644 | if (status == CBM_USERCONFIG_SNAPSHOT_OK && extra) { |
| 645 | yyjson_obj_iter iter; |
| 646 | yyjson_obj_iter_init(extra, &iter); |
| 647 | yyjson_val *key; |
| 648 | while ((key = yyjson_obj_iter_next(&iter)) != NULL) { |
| 649 | status = snapshot_entry(arena, cfg, key, yyjson_obj_iter_get_val(key)); |
| 650 | if (status != CBM_USERCONFIG_SNAPSHOT_OK) |
| 651 | break; |
| 652 | } |
| 653 | } |
| 654 | yyjson_doc_free(doc); |
| 655 | return status; |
| 656 | } |
| 657 | |
| 658 | static cbm_userconfig_snapshot_status_t snapshot_input(cbm_userconfig_source_state_t state, |
| 659 | const void *bytes, size_t len) { |
no test coverage detected