Skip to content

Commit 809b082

Browse files
committed
Handle 0 chunk schunks in get_slice_nchunks
1 parent 4899eae commit 809b082

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

blosc/schunk.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,10 @@ int blosc2_schunk_set_slice_buffer(blosc2_schunk *schunk, int64_t start, int64_t
13931393

13941394
int schunk_get_slice_nchunks(blosc2_schunk *schunk, int64_t start, int64_t stop, int64_t **chunks_idx) {
13951395
BLOSC_ERROR_NULL(schunk, BLOSC2_ERROR_NULL_POINTER);
1396-
1396+
if (schunk->nchunks == 0){
1397+
*chunks_idx = malloc(0);
1398+
return 0;
1399+
}
13971400
int64_t byte_start = start * schunk->typesize;
13981401
int64_t byte_stop = stop * schunk->typesize;
13991402
int64_t nchunk_start = byte_start / schunk->chunksize;

tests/test_get_slice_nchunks.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ test_ndata tndata[] = {
4646
{5, 0, CHUNKSIZE * 5 + 200 * 100 + 300, true, 0, 6}, // last chunk shorter
4747
{2, 10, CHUNKSIZE * 2 + 400, true, 0, 3}, // start != 0, last chunk shorter
4848
{12, CHUNKSIZE * 1 + 300, CHUNKSIZE * 4 + 100, false, 1, 5}, // start not in first chunk
49+
{0, 0, 100, false, 0, 0}, // shape 0 array
4950
};
5051

5152
typedef struct {
@@ -84,6 +85,8 @@ static char* test_get_slice_nchunks(void) {
8485
.urlpath=tdata.urlpath, .contiguous=tdata.contiguous};
8586
schunk = blosc2_schunk_new(&storage);
8687

88+
if (tdata.nchunks == 0){schunk->chunksize = 0;}
89+
8790
// Feed it with data
8891
if (!tdata.shorter_last_chunk) {
8992
for (int nchunk = 0; nchunk < tdata.nchunks; nchunk++) {

0 commit comments

Comments
 (0)