Skip to content

Commit

Permalink
Merge pull request #692 from eregon/fix_read_string_zero_encoding
Browse files Browse the repository at this point in the history
Fix FFI::Pointer#read_string(0) to return a binary String
  • Loading branch information
larskanis committed Apr 12, 2019
2 parents 6d05806 + 4c92387 commit 59934bb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ffi/pointer.rb
Expand Up @@ -49,7 +49,7 @@ def self.size
# equivalent string if +len+ is not +nil+.
def read_string(len=nil)
if len
return '' if len == 0
return ''.b if len == 0
get_bytes(0, len)
else
get_string(0)
Expand Down
1 change: 1 addition & 0 deletions spec/ffi/rbx/memory_pointer_spec.rb
Expand Up @@ -37,6 +37,7 @@ module CTest

it "reads back an empty string" do
expect(FFI::Pointer::NULL.read_string(0)).to eq('')
expect(FFI::Pointer::NULL.read_string(0).encoding).to eq(Encoding::BINARY)
end

it "makes a pointer for a certain number of bytes" do
Expand Down

0 comments on commit 59934bb

Please sign in to comment.