Skip to content

Commit

Permalink
[ELF] Catch zlib deflateInit2 error
Browse files Browse the repository at this point in the history
The function may return Z_MEM_ERROR or Z_STREAM_ERR. The former does not
have a good way of testing. The latter will be possible with a pending
change that allows setting the compression level, which will come with a
test.
  • Loading branch information
MaskRay committed May 1, 2024
1 parent 1ca6005 commit 91fef00
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lld/ELF/OutputSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,11 @@ static SmallVector<uint8_t, 0> deflateShard(ArrayRef<uint8_t> in, int level,
// 15 and 8 are default. windowBits=-15 is negative to generate raw deflate
// data with no zlib header or trailer.
z_stream s = {};
deflateInit2(&s, level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
auto res = deflateInit2(&s, level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
if (res != 0) {
errorOrWarn("--compress-sections: deflateInit2 returned " + Twine(res));
return {};
}
s.next_in = const_cast<uint8_t *>(in.data());
s.avail_in = in.size();

Expand Down

0 comments on commit 91fef00

Please sign in to comment.