Skip to content

Commit e294b8f

Browse files
committed
dumb changes came back
1 parent 76f62a7 commit e294b8f

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎pack.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,6 @@ pack_pack(rb_execution_context_t *ec, VALUE ary, VALUE fmt, VALUE buffer)
778778
size_t numbytes, nlz_bits;
779779
int sign, extra = 0;
780780
char *cp;
781-
const long start = RSTRING_LEN(res);
782781

783782
from = NEXTFROM;
784783
from = rb_to_int(from);
@@ -796,6 +795,8 @@ pack_pack(rb_execution_context_t *ec, VALUE ary, VALUE fmt, VALUE buffer)
796795
}
797796
rb_str_modify_expand(res, numbytes + extra);
798797

798+
long start = RSTRING_LEN(res);
799+
799800
cp = RSTRING_PTR(res) + start;
800801
sign = rb_integer_pack(from, cp, numbytes, 1, 1, pack_flags);
801802

‎test/ruby/test_pack.rb‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,20 @@ class Array
10071007
end;
10081008
end
10091009

1010+
def test_pack_modify_buffer_r_R
1011+
buf = "x" * 10_000
1012+
o = Object.new
1013+
o.define_singleton_method(:to_int) { buf.clear; 1 }
1014+
[o, 42].pack("R R", buffer: buf)
1015+
assert_equal "\x01\x2A".b, buf
1016+
1017+
buf = "x" * 10_000
1018+
o = Object.new
1019+
o.define_singleton_method(:to_int) { buf.clear; -2 }
1020+
[o].pack("r", buffer: buf)
1021+
assert_equal "\x7E".b, buf
1022+
end
1023+
10101024
def test_unpack_broken_R
10111025
assert_equal([nil], "\xFF".unpack("R"))
10121026
assert_nil("\xFF".unpack1("R"))

0 commit comments

Comments
 (0)