Skip to content

Commit

Permalink
[Compression] Correctly try to reallocate only when no output data.
Browse files Browse the repository at this point in the history
This is a fix of bug introduced with commit a7201ce.

Fix #578
  • Loading branch information
mgautierfr authored and kelson42 committed Jul 31, 2021
1 parent 6b69bc0 commit d915b18
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,19 @@ class Compressor
}
case CompStatus::STREAM_END:
return RunnerStatus::NEED_MORE;
case CompStatus::BUF_ERROR: {
//Not enought output size
ret_size *= 2;
std::unique_ptr<char[]> new_ret_data(new char[ret_size]);
memcpy(new_ret_data.get(), ret_data.get(), stream.total_out);
stream.next_out = (unsigned char*)(new_ret_data.get() + stream.total_out);
stream.avail_out = ret_size - stream.total_out;
ret_data = std::move(new_ret_data);
continue;
}
case CompStatus::BUF_ERROR:
if (stream.avail_out == 0) {
//Not enought output size
ret_size *= 2;
std::unique_ptr<char[]> new_ret_data(new char[ret_size]);
memcpy(new_ret_data.get(), ret_data.get(), stream.total_out);
stream.next_out = (unsigned char*)(new_ret_data.get() + stream.total_out);
stream.avail_out = ret_size - stream.total_out;
ret_data = std::move(new_ret_data);
continue;
} else {
return RunnerStatus::ERROR;
}
break;
default:
// unreachable
Expand Down

0 comments on commit d915b18

Please sign in to comment.