Skip to content

Commit 3974457

Browse files
committed
Fix LibHTS.htell to use proper pointer arithmetic
1 parent eae4297 commit 3974457

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

lib/hts/libhts/hfile.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ module LibHTS
4646

4747
# Report the current stream offset
4848
def self.htell(fp)
49-
# TODO: This is a hack. Is this OK?
50-
bg = FFI::Pointer.new(:int, fp.pointer.address + fp.offset_of(:begin)).read_int
51-
bf = FFI::Pointer.new(:int, fp.pointer.address + fp.offset_of(:buffer)).read_int
52-
fp[:offset] + (bg - bf)
49+
base_ptr = fp.pointer
50+
begin_ptr = base_ptr.get_pointer(fp.offset_of(:begin))
51+
buffer_ptr = base_ptr.get_pointer(fp.offset_of(:buffer))
52+
fp[:offset] + (begin_ptr.address - buffer_ptr.address)
5353
end
5454

5555
# Read from the stream until the delimiter, up to a maximum length

0 commit comments

Comments
 (0)