Skip to content

Commit e2dcf9d

Browse files
committed
Ensure touching pending buffer
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent d33423a commit e2dcf9d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ext/zstdruby/streaming_compress.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ rb_streaming_compress_write(int argc, VALUE *argv, VALUE obj)
158158
const char* input_data = RSTRING_PTR(str);
159159
size_t input_size = RSTRING_LEN(str);
160160
ZSTD_inBuffer input = { input_data, input_size, 0 };
161+
VALUE result = rb_str_new(0, 0);
161162

162163
while (input.pos < input.size) {
163164
ZSTD_outBuffer output = { (void*)output_data, sc->buf_size, 0 };
@@ -167,9 +168,10 @@ rb_streaming_compress_write(int argc, VALUE *argv, VALUE obj)
167168
}
168169
/* collect produced bytes */
169170
if (output.pos > 0) {
170-
rb_str_cat(sc->pending, output.dst, output.pos);
171+
rb_str_cat(result, output.dst, output.pos);
171172
}
172173
}
174+
rb_str_cat(sc->pending, RSTRING_PTR(result), RSTRING_LEN(result));
173175
total += RSTRING_LEN(str);
174176
}
175177

0 commit comments

Comments
 (0)