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