Skip to content

Commit

Permalink
igzip: add zlib header init function
Browse files Browse the repository at this point in the history
Add isal_zlib_hdr_init() function to initialize
the isal_zlib_header structure to all 0.

Signed-off-by: Pablo de Lara <[email protected]>
  • Loading branch information
pablodelara authored and tkanteck committed Dec 20, 2023
1 parent 6ef2abe commit 29d99fc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
8 changes: 8 additions & 0 deletions igzip/igzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,14 @@ void isal_gzip_header_init(struct isal_gzip_header *gz_hdr)
gz_hdr->flags = 0;
}

void isal_zlib_header_init(struct isal_zlib_header *z_hdr)
{
z_hdr->info = 0;
z_hdr->level = 0;
z_hdr->dict_id = 0;
z_hdr->dict_flag = 0;
}

uint32_t isal_write_gzip_header(struct isal_zstream *stream, struct isal_gzip_header *gz_hdr)
{
uint32_t flags = 0, hcrc, hdr_size = GZIP_HDR_BASE;
Expand Down
10 changes: 8 additions & 2 deletions igzip/igzip_inflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2195,12 +2195,15 @@ int isal_inflate_stateless(struct inflate_state *state)

if (state->crc_flag == IGZIP_GZIP) {
struct isal_gzip_header gz_hdr;

isal_gzip_header_init(&gz_hdr);
ret = isal_read_gzip_header(state, &gz_hdr);
if (ret)
return ret;
} else if (state->crc_flag == IGZIP_ZLIB) {
struct isal_zlib_header z_hdr = { 0 };
struct isal_zlib_header z_hdr;

isal_zlib_header_init(&z_hdr);
ret = isal_read_zlib_header(state, &z_hdr);
if (ret)
return ret;
Expand Down Expand Up @@ -2268,14 +2271,17 @@ int isal_inflate(struct inflate_state *state)

if (!state->wrapper_flag && state->crc_flag == IGZIP_GZIP) {
struct isal_gzip_header gz_hdr;

isal_gzip_header_init(&gz_hdr);
ret = isal_read_gzip_header(state, &gz_hdr);
if (ret < 0)
return ret;
else if (ret > 0)
return ISAL_DECOMP_OK;
} else if (!state->wrapper_flag && state->crc_flag == IGZIP_ZLIB) {
struct isal_zlib_header z_hdr = { 0 };
struct isal_zlib_header z_hdr;

isal_zlib_header_init(&z_hdr);
ret = isal_read_zlib_header(state, &z_hdr);
if (ret < 0)
return ret;
Expand Down
2 changes: 1 addition & 1 deletion igzip/igzip_wrapper_hdr_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ int main(int argc, char *argv[])

printf("zlib wrapper test: ");
for (i = 0; i < RANDOMS; i++) {
memset(&z_hdr_orig, 0, sizeof(z_hdr_orig));
isal_zlib_header_init(&z_hdr_orig);

gen_rand_zlib_header(&z_hdr_orig);

Expand Down
7 changes: 7 additions & 0 deletions include/igzip_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,13 @@ void isal_deflate_reset(struct isal_zstream *stream);
*/
void isal_gzip_header_init(struct isal_gzip_header *gz_hdr);

/**
* @brief Set zlib header default values
*
* @param z_hdr: zlib header to initialize.
*/
void isal_zlib_header_init(struct isal_zlib_header *z_hdr);

/**
* @brief Write gzip header to output stream
*
Expand Down
1 change: 1 addition & 0 deletions isa-l.def
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,4 @@ crc64_rocksoft_refl_base @116
crc64_rocksoft_norm @117
crc64_rocksoft_refl @118
ec_init_tables_base @119
isal_zlib_header_init @120

0 comments on commit 29d99fc

Please sign in to comment.