Resolve the DB path for this pipeline. Caller must free(). */
| 519 | |
| 520 | /* Resolve the DB path for this pipeline. Caller must free(). */ |
| 521 | static char *resolve_db_path(const cbm_pipeline_t *p) { |
| 522 | if (!p) { |
| 523 | return NULL; |
| 524 | } |
| 525 | if (p->db_path) { |
| 526 | return strdup(p->db_path); |
| 527 | } |
| 528 | |
| 529 | const char *cache_dir = cbm_resolve_cache_dir(); |
| 530 | cache_dir = cache_dir ? cache_dir : cbm_tmpdir(); |
| 531 | if (!cache_dir || !p->project_name) { |
| 532 | return NULL; |
| 533 | } |
| 534 | size_t cache_len = strlen(cache_dir); |
| 535 | size_t project_len = strlen(p->project_name); |
| 536 | if (project_len > SIZE_MAX - cache_len) { |
| 537 | return NULL; |
| 538 | } |
| 539 | size_t stem_len = cache_len + project_len; |
| 540 | if (stem_len > SIZE_MAX - sizeof("/.db")) { |
| 541 | return NULL; |
| 542 | } |
| 543 | size_t path_size = stem_len + sizeof("/.db"); |
| 544 | char *path = malloc(path_size); |
| 545 | if (!path) { |
| 546 | return NULL; |
| 547 | } |
| 548 | int n = snprintf(path, path_size, "%s/%s.db", cache_dir, p->project_name); |
| 549 | if (n < 0 || (size_t)n >= path_size) { |
| 550 | free(path); |
| 551 | return NULL; |
| 552 | } |
| 553 | return path; |
| 554 | } |
| 555 | |
| 556 | static int check_cancel(const cbm_pipeline_t *p) { |
| 557 | return atomic_load(p->cancelled) ? CBM_NOT_FOUND : 0; |
no test coverage detected