Skip to content

Commit

Permalink
Fix insert_chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
martaiborra committed Jun 30, 2022
1 parent d4bf086 commit 46ebf8e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
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

0 comments on commit 46ebf8e

Please sign in to comment.