Skip to content

Commit 4deb619

Browse files
committed
wip
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 89553f2 commit 4deb619

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/cio_file.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,12 @@ int cio_file_sync(struct cio_chunk *ch)
11351135
return 0;
11361136
}
11371137

1138+
/* Check if file is mapped before accessing cf->map */
1139+
/* This must be checked before accessing cf->map in finalize_checksum() */
1140+
if (!cio_file_native_is_mapped(cf)) {
1141+
return -1;
1142+
}
1143+
11381144
if (cf->synced == CIO_TRUE) {
11391145
return 0;
11401146
}

tests/fs_windows.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,15 @@ static void test_win32_sync_without_map()
236236
TEST_CHECK(cio_chunk_is_up(chunk) == CIO_FALSE);
237237
printf("Verified: chunk is down (not mapped)\n");
238238

239+
/* Set synced flag to FALSE to force sync path (since cio_file_down syncs before unmapping) */
240+
cf->synced = CIO_FALSE;
241+
239242
/* Try to sync without mapping using public API */
240-
/* On Windows, cio_file_native_sync (called by cio_file_sync) should check if mapped first */
243+
/* cio_file_sync should check if file is mapped before accessing cf->map */
241244
printf("Attempting sync on unmapped file using cio_file_sync()...\n");
242-
printf("cio_file_sync() internally calls cio_file_native_sync() which should validate mapping\n");
245+
printf("cio_file_sync() should check if mapped before accessing cf->map\n");
243246

244-
/* Use public API to sync - this internally calls cio_file_native_sync */
247+
/* Use public API to sync - this should fail because file is not mapped */
245248
ret = cio_file_sync(chunk);
246249
printf("Result of sync without map: %d (expected: -1 for error)\n", ret);
247250

0 commit comments

Comments
 (0)