Skip to content

Commit

Permalink
* pack.c (pack_pack): fixed length for odd length string.
Browse files Browse the repository at this point in the history
  [ruby-dev:37283]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20580 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Dec 8, 2008
1 parent 774f924 commit 92e0f99
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Mon Dec 8 18:31:41 2008 Nobuyoshi Nakada <[email protected]>

* pack.c (pack_pack): fixed length for odd length string.
[ruby-dev:37283]

Mon Dec 8 11:28:14 2008 Nobuyoshi Nakada <[email protected]>

* ruby.c (proc_options): added version, copyright, usage, yydebug,
Expand Down
4 changes: 2 additions & 2 deletions pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ pack_pack(VALUE ary, VALUE fmt)
long i, j = 0;

if (len > plen) {
j = (len - plen + 1)/2;
j = (len + 1) / 2 - (plen + 1) / 2;
len = plen;
}
for (i=0; i++ < len; ptr++) {
Expand Down Expand Up @@ -651,7 +651,7 @@ pack_pack(VALUE ary, VALUE fmt)
long i, j = 0;

if (len > plen) {
j = (len - plen + 1)/2;
j = (len + 1) / 2 - (plen + 1) / 2;
len = plen;
}
for (i=0; i++ < len; ptr++) {
Expand Down
12 changes: 12 additions & 0 deletions test/ruby/test_pack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,23 @@ def test_pack_unpack_hH
assert_equal("", ["10ef"].pack("h0"))
assert_equal("\x01\x0e", ["10ef"].pack("h3"))
assert_equal("\x01\xfe\x0", ["10ef"].pack("h5"))
assert_equal("\xff\x0f", ["fff"].pack("h3"))
assert_equal("\xff\x0f", ["fff"].pack("h4"))
assert_equal("\xff\x0f\0", ["fff"].pack("h5"))
assert_equal("\xff\x0f\0", ["fff"].pack("h6"))
assert_equal("\xff\x0f\0\0", ["fff"].pack("h7"))
assert_equal("\xff\x0f\0\0", ["fff"].pack("h8"))

assert_equal("\x10\xef", ["10ef"].pack("H*"))
assert_equal("", ["10ef"].pack("H0"))
assert_equal("\x10\xe0", ["10ef"].pack("H3"))
assert_equal("\x10\xef\x0", ["10ef"].pack("H5"))
assert_equal("\xff\xf0", ["fff"].pack("H3"))
assert_equal("\xff\xf0", ["fff"].pack("H4"))
assert_equal("\xff\xf0\0", ["fff"].pack("H5"))
assert_equal("\xff\xf0\0", ["fff"].pack("H6"))
assert_equal("\xff\xf0\0\0", ["fff"].pack("H7"))
assert_equal("\xff\xf0\0\0", ["fff"].pack("H8"))

assert_equal(["10ef"], "\x01\xfe".unpack("h*"))
assert_equal([""], "\x01\xfe".unpack("h0"))
Expand Down

0 comments on commit 92e0f99

Please sign in to comment.