Skip to content

Commit 81e3cea

Browse files
committed
Check the return value inside of the loop
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent d1ed823 commit 81e3cea

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

ext/zstdruby/streaming_decompress.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,15 @@ rb_streaming_decompress_decompress(VALUE obj, VALUE src)
102102
TypedData_Get_Struct(obj, struct streaming_decompress_t, &streaming_decompress_type, sd);
103103
const char* output_data = RSTRING_PTR(sd->buf);
104104
VALUE result = rb_str_new(0, 0);
105-
while (input.pos < input.size) {
105+
size_t ret;
106+
do {
106107
ZSTD_outBuffer output = { (void*)output_data, sd->buf_size, 0 };
107-
size_t const ret = zstd_stream_decompress(sd->dctx, &output, &input, false);
108+
ret = zstd_stream_decompress(sd->dctx, &output, &input, false);
108109
if (ZSTD_isError(ret)) {
109110
rb_raise(rb_eRuntimeError, "decompress error error code: %s", ZSTD_getErrorName(ret));
110111
}
111112
rb_str_cat(result, output.dst, output.pos);
112-
}
113+
} while (input.pos < input.size && ret > 0);
113114
return result;
114115
}
115116

0 commit comments

Comments
 (0)