Skip to content

Commit 08731db

Browse files
tenderlovenobu
andauthored
Update pack.c
Co-authored-by: Nobuyoshi Nakada <[email protected]>
1 parent cd2482b commit 08731db

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pack.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,9 @@ pack_pack(rb_execution_context_t *ec, VALUE ary, VALUE fmt, VALUE buffer)
680680
numbytes = rb_absint_numwords(from, 7, NULL);
681681
if (numbytes == 0)
682682
numbytes = 1;
683-
buf = rb_str_new(NULL, numbytes);
684-
685-
sign = rb_integer_pack(from, RSTRING_PTR(buf), RSTRING_LEN(buf), 1, 1, INTEGER_PACK_LITTLE_ENDIAN | INTEGER_PACK_2COMP);
683+
rb_str_modify_expand(res, numbytes);
684+
cp = RSTRING_END(res);
685+
sign = rb_integer_pack(from, cp, numbytes, 1, 1, INTEGER_PACK_LITTLE_ENDIAN | INTEGER_PACK_2COMP);
686686

687687
/* Check if we need an extra byte for sign extension */
688688
last_byte = (unsigned char)RSTRING_PTR(buf)[numbytes - 1];

0 commit comments

Comments
 (0)