Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix insert_chunk #408

Merged
merged 1 commit into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions blosc/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -2745,8 +2745,9 @@ void* frame_insert_chunk(blosc2_frame_s* frame, int64_t nchunk, void* chunk, blo
break;
default:
if (frame->sframe) {
for (int i = 0; i < nchunks; ++i) {
if (offsets[i] > sframe_chunk_id) {
for (int i = 0; i <= nchunks; ++i) {
// offsets[nchunk] is still uninitialized here
if (offsets[i] > sframe_chunk_id && i != nchunk) {
sframe_chunk_id = offsets[i];
}
}
Expand Down
23 changes: 21 additions & 2 deletions tests/test_insert_chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static char* test_insert_chunk(void) {
for (int i = 0; i < tdata.ninsertions; ++i) {
// Create chunk
for (int j = 0; j < CHUNKSIZE; ++j) {
data[j] = i;
data[j] = i - 1;
}
int32_t datasize = sizeof(int64_t) * CHUNKSIZE;
int32_t chunksize = sizeof(int64_t) * CHUNKSIZE + BLOSC_MAX_OVERHEAD;
Expand All @@ -121,8 +121,27 @@ static char* test_insert_chunk(void) {
mu_assert("ERROR: chunk cannot be decompressed correctly", dsize >= 0);
for (int j = 0; j < CHUNKSIZE; j++) {
int64_t a = data_dest[j];
mu_assert("ERROR: bad roundtrip", a == i);
mu_assert("ERROR: bad roundtrip2", a == i - 1);
}
if (i == 0) {
// Check that the other chunks have not changed
for (int nchunk = 0; nchunk < pos; nchunk++) {
dsize = blosc2_schunk_decompress_chunk(schunk, nchunk, (void *) data_dest, isize);
mu_assert("ERROR: chunk cannot be decompressed correctly.", dsize >= 0);
for (int j = 0; j < CHUNKSIZE; j++) {
mu_assert("ERROR: bad roundtrip3",data_dest[j] == j + nchunk * CHUNKSIZE);
}
}
for (int nchunk = pos + 1; nchunk < tdata.nchunks + 1; nchunk++) {
dsize = blosc2_schunk_decompress_chunk(schunk, nchunk, (void *) data_dest, isize);
mu_assert("ERROR: chunk cannot be decompressed correctly.", dsize >= 0);
for (int j = 0; j < CHUNKSIZE; j++) {
mu_assert("ERROR: bad roundtrip4",data_dest[j] == j + (nchunk - 1) * CHUNKSIZE);
}
}

}

// Free allocated chunk
if (tdata.copy) {
free(chunk);
Expand Down