@@ -212,7 +212,7 @@ char *twobitSequence(TwoBit *tb, char *chrom, uint32_t start, uint32_t end) {
212212 break ;
213213 }
214214 }
215- if (tid == 0 && strcmp (tb -> cl -> chrom [i ], chrom ) != 0 ) return NULL ;
215+ if (tid == 0 && strcmp (tb -> cl -> chrom [tid ], chrom ) != 0 ) return NULL ;
216216
217217 //Get the start/end if not specified
218218 if (start == end && end == 0 ) {
@@ -406,7 +406,7 @@ void *twobitBases(TwoBit *tb, char *chrom, uint32_t start, uint32_t end, int fra
406406 }
407407 }
408408
409- if (tid == 0 && strcmp (tb -> cl -> chrom [i ], chrom ) != 0 ) return NULL ;
409+ if (tid == 0 && strcmp (tb -> cl -> chrom [tid ], chrom ) != 0 ) return NULL ;
410410
411411 //Get the start/end if not specified
412412 if (start == end && end == 0 ) {
@@ -517,7 +517,7 @@ void twobitIndexRead(TwoBit *tb, int storeMasked) {
517517 for (i = 0 ; i < tb -> hdr -> nChroms ; i ++ ) {
518518 if (idx -> nBlockSizes [i ]) free (idx -> nBlockSizes [i ]);
519519 }
520- free (idx -> nBlockSizes [ i ] );
520+ free (idx -> nBlockSizes );
521521 }
522522
523523 if (idx -> maskBlockCount ) free (idx -> maskBlockCount );
@@ -587,13 +587,15 @@ void twobitChromListRead(TwoBit *tb) {
587587 TwoBitCL * cl = calloc (1 , sizeof (TwoBitCL ));
588588 uint8_t useLong = tb -> hdr -> version == 1 ;
589589 size_t offsetSz = (useLong ) ? sizeof (uint64_t ) : sizeof (uint32_t );
590+ void * offset = calloc (1 , offsetSz );
590591
591592 //Allocate cl and do error checking
592593 if (!cl ) goto error ;
593594 cl -> chrom = calloc (tb -> hdr -> nChroms , sizeof (char * ));
594- cl -> offset = calloc (tb -> hdr -> nChroms , offsetSz );
595+ cl -> offset = calloc (tb -> hdr -> nChroms , sizeof ( uint64_t ) );
595596 if (!cl -> chrom ) goto error ;
596597 if (!cl -> offset ) goto error ;
598+ if (!offset ) goto error ;
597599
598600 for (i = 0 ; i < tb -> hdr -> nChroms ; i ++ ) {
599601 //Get the string size (not null terminated!)
@@ -607,8 +609,14 @@ void twobitChromListRead(TwoBit *tb) {
607609 str = NULL ;
608610
609611 //Read in the size
610- if (twobitRead (cl -> offset + i , offsetSz , 1 , tb ) != 1 ) goto error ;
612+ if (twobitRead (offset , offsetSz , 1 , tb ) != 1 ) goto error ;
613+ if (useLong ) {
614+ cl -> offset [i ] = * ((uint64_t * ) offset );
615+ } else {
616+ cl -> offset [i ] = * ((uint32_t * ) offset );
617+ }
611618 }
619+ free (offset );
612620
613621 tb -> cl = cl ;
614622 return ;
@@ -625,6 +633,7 @@ void twobitChromListRead(TwoBit *tb) {
625633 }
626634 free (cl );
627635 }
636+ if (offset ) free (offset );
628637}
629638
630639void twobitChromListDestroy (TwoBit * tb ) {
0 commit comments