Skip to content
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
11 changes: 7 additions & 4 deletions 2bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ void twobitIndexRead(TwoBit *tb, int storeMasked) {
if(!idx->nBlockStart) goto error;
if(!idx->nBlockSizes) goto error;
idx->maskBlockCount = calloc(tb->hdr->nChroms, sizeof(uint32_t));

if(!idx->maskBlockCount) goto error;
if(storeMasked) {
idx->maskBlockStart = calloc(tb->hdr->nChroms, sizeof(uint32_t*));
Expand Down Expand Up @@ -584,11 +585,13 @@ void twobitChromListRead(TwoBit *tb) {
uint8_t byte;
char *str = NULL;
TwoBitCL *cl = calloc(1, sizeof(TwoBitCL));
uint8_t useLong = tb->hdr->version == 1;
size_t offsetSz = (useLong) ? sizeof(uint64_t) : sizeof(uint32_t);

//Allocate cl and do error checking
if(!cl) goto error;
cl->chrom = calloc(tb->hdr->nChroms, sizeof(char*));
cl->offset = malloc(sizeof(uint32_t) * tb->hdr->nChroms);
cl->offset = calloc(tb->hdr->nChroms, offsetSz);
if(!cl->chrom) goto error;
if(!cl->offset) goto error;

Expand All @@ -604,7 +607,7 @@ void twobitChromListRead(TwoBit *tb) {
str = NULL;

//Read in the size
if(twobitRead(cl->offset + i, sizeof(uint32_t), 1, tb) != 1) goto error;
if(twobitRead(cl->offset + i, offsetSz, 1, tb) != 1) goto error;
}

tb->cl = cl;
Expand Down Expand Up @@ -657,8 +660,8 @@ void twobitHdrRead(TwoBit *tb) {

//Version
hdr->version = data[1];
if(hdr->version != 0) {
fprintf(stderr, "[twobitHdrRead] The file version is %"PRIu32" while only version 0 is defined!\n", hdr->version);
if(hdr->version != 0 && hdr->version != 1) {
fprintf(stderr, "[twobitHdrRead] The file version is %"PRIu32" while only versions 0 and 1 are defined!\n", hdr->version);
goto error;
}

Expand Down
2 changes: 1 addition & 1 deletion 2bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typedef struct {
*/
typedef struct {
char **chrom; /**<A list of null terminated chromosomes */
uint32_t *offset; /**<The file offset for the beginning of each chromosome */
uint64_t *offset; /**<The file offset for the beginning of each chromosome */
} TwoBitCL;

/*!
Expand Down
Loading