Skip to content

Commit

Permalink
Fixed Slice#hexdump for empty slice. Fixes #3906
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Jan 17, 2017
1 parent ce1b6d6 commit aca9433
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spec/std/slice_spec.cr
Expand Up @@ -234,6 +234,10 @@ describe "Slice" do
slice.hexstring.should eq("01020304")
end

it "does hexdump for empty slice" do
Bytes.empty.hexdump.should eq("")
end

it "does hexdump" do
ascii_table = <<-EOF
00000000 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f !"#$%&'()*+,-./
Expand Down
2 changes: 2 additions & 0 deletions src/slice.cr
Expand Up @@ -329,6 +329,8 @@ struct Slice(T)
def hexdump
self.as(Slice(UInt8))

return "" if empty?

full_lines, leftover = size.divmod(16)
if leftover == 0
str_size = full_lines * 77 - 1
Expand Down

0 comments on commit aca9433

Please sign in to comment.