@@ -275,7 +275,7 @@ uint8_t getByteMaskFromOffset(int offset) {
275
275
276
276
void * twobitBasesWorker (TwoBit * tb , uint32_t tid , uint32_t start , uint32_t end , int fraction ) {
277
277
void * out ;
278
- uint32_t tmp [4 ] = {0 , 0 , 0 , 0 }, len = end - start , i = 0 , j = 0 ;
278
+ uint32_t tmp [4 ] = {0 , 0 , 0 , 0 }, len = end - start + ( start % 4 ) , i = 0 , j = 0 ;
279
279
uint32_t blockStart , blockEnd , maskIdx = (uint32_t ) -1 , maskStart , maskEnd , foo ;
280
280
uint8_t * bytes = NULL , mask = 0 , offset ;
281
281
@@ -293,8 +293,10 @@ void *twobitBasesWorker(TwoBit *tb, uint32_t tid, uint32_t start, uint32_t end,
293
293
bytes = malloc (blockEnd - blockStart );
294
294
if (!bytes ) goto error ;
295
295
296
- //Set the initial mask
296
+ //Set the initial mask, reset start/offset so we always deal with full bytes
297
297
mask = getByteMaskFromOffset (offset );
298
+ start = 4 * blockStart ;
299
+ offset = 0 ;
298
300
299
301
if (twobitSeek (tb , tb -> idx -> offset [tid ] + blockStart ) != 0 ) goto error ;
300
302
if (twobitRead (bytes , blockEnd - blockStart , 1 , tb ) != 1 ) goto error ;
0 commit comments