Fix P1 review findings in pfstasks_db test and helpers

1. Check psql_test_exec() return values in test_cascade_delete() and
   test_creat_after_unlink() consistently with test_fstaskdepend_insert().
2. Remove dead dep_cnt variable and (void)dep_cnt suppressor from
   test_creat_after_unlink().
3. Change SQLITE_STATIC → SQLITE_TRANSIENT for text1 binding in
   psql_test_insert_fstask() to avoid dangling-pointer footgun on
   future reuse.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Levi Neely 2026-03-10 19:53:16 +01:00
parent 82aaf83d9a
commit 92bfab2ba4
2 changed files with 7 additions and 7 deletions

View File

@ -88,7 +88,7 @@ int64_t psql_test_insert_fstask(int type, int status, int64_t folderid,
sqlite3_bind_int64(stmt, 3, folderid);
sqlite3_bind_int64(stmt, 4, folderid);
if (text1)
sqlite3_bind_text(stmt, 5, text1, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 5, text1, -1, SQLITE_TRANSIENT);
else
sqlite3_bind_null(stmt, 5);
int rc = sqlite3_step(stmt);

View File

@ -124,12 +124,14 @@ static void test_cascade_delete(void) {
snprintf(sql, sizeof(sql),
"INSERT INTO fstaskdepend (fstaskid, dependfstaskid) VALUES (%lld, %lld)",
(long long)child, (long long)parent);
psql_test_exec(sql);
if (psql_test_exec(sql) != SQLITE_OK)
{ FAIL("cascade: insert depend", "exec failed"); return; }
/* Delete the parent task */
snprintf(sql, sizeof(sql), "DELETE FROM fstask WHERE id=%lld",
(long long)parent);
psql_test_exec(sql);
if (psql_test_exec(sql) != SQLITE_OK)
{ FAIL("cascade: delete parent", "exec failed"); return; }
/* Both the parent row AND the dependency row should be gone */
char where[128];
@ -230,14 +232,14 @@ static void test_creat_after_unlink(void) {
snprintf(sql, sizeof(sql),
"INSERT INTO fstaskdepend (fstaskid, dependfstaskid) VALUES (%lld, %lld)",
(long long)creat_id, (long long)unlink_id);
psql_test_exec(sql);
if (psql_test_exec(sql) != SQLITE_OK)
{ FAIL("creat-after-unlink: insert depend", "exec failed"); return; }
/* Verify both tasks exist for this folderid+name */
int unlink_cnt = psql_test_count_fstask(
"type=4 AND folderid=600 AND text1='data.bin'");
int creat_cnt = psql_test_count_fstask(
"type=3 AND folderid=600 AND text1='data.bin'");
int dep_cnt = psql_test_count_fstaskdepend(NULL);
if (unlink_cnt == 1 && creat_cnt == 1)
PASS("creat-after-unlink: UNLINK and CREAT tasks both recorded");
@ -255,8 +257,6 @@ static void test_creat_after_unlink(void) {
PASS("creat-after-unlink: CREAT depends on UNLINK in fstaskdepend");
else
FAIL("creat-after-unlink dependency", "dep_count=%d expected 1", d);
(void)dep_cnt;
}
/* ------------------------------------------------------------------ */