@@ -452,6 +452,7 @@ void twobitIndexRead(TwoBit *tb, int storeMasked) {
452452 if (!idx -> nBlockStart ) goto error ;
453453 if (!idx -> nBlockSizes ) goto error ;
454454 idx -> maskBlockCount = calloc (tb -> hdr -> nChroms , sizeof (uint32_t ));
455+
455456 if (!idx -> maskBlockCount ) goto error ;
456457 if (storeMasked ) {
457458 idx -> maskBlockStart = calloc (tb -> hdr -> nChroms , sizeof (uint32_t * ));
@@ -584,11 +585,13 @@ void twobitChromListRead(TwoBit *tb) {
584585 uint8_t byte ;
585586 char * str = NULL ;
586587 TwoBitCL * cl = calloc (1 , sizeof (TwoBitCL ));
588+ uint8_t useLong = tb -> hdr -> version == 1 ;
589+ size_t offsetSz = (useLong ) ? sizeof (uint64_t ) : sizeof (uint32_t );
587590
588591 //Allocate cl and do error checking
589592 if (!cl ) goto error ;
590593 cl -> chrom = calloc (tb -> hdr -> nChroms , sizeof (char * ));
591- cl -> offset = malloc ( sizeof ( uint32_t ) * tb -> hdr -> nChroms );
594+ cl -> offset = calloc ( tb -> hdr -> nChroms , offsetSz );
592595 if (!cl -> chrom ) goto error ;
593596 if (!cl -> offset ) goto error ;
594597
@@ -604,7 +607,7 @@ void twobitChromListRead(TwoBit *tb) {
604607 str = NULL ;
605608
606609 //Read in the size
607- if (twobitRead (cl -> offset + i , sizeof ( uint32_t ) , 1 , tb ) != 1 ) goto error ;
610+ if (twobitRead (cl -> offset + i , offsetSz , 1 , tb ) != 1 ) goto error ;
608611 }
609612
610613 tb -> cl = cl ;
@@ -657,8 +660,8 @@ void twobitHdrRead(TwoBit *tb) {
657660
658661 //Version
659662 hdr -> version = data [1 ];
660- if (hdr -> version != 0 ) {
661- fprintf (stderr , "[twobitHdrRead] The file version is %" PRIu32 " while only version 0 is defined!\n" , hdr -> version );
663+ if (hdr -> version != 0 && hdr -> version != 1 ) {
664+ fprintf (stderr , "[twobitHdrRead] The file version is %" PRIu32 " while only versions 0 and 1 are defined!\n" , hdr -> version );
662665 goto error ;
663666 }
664667
0 commit comments