From 29d99fce2631c435b37b6c6842aa18da41ce83a6 Mon Sep 17 00:00:00 2001 From: Pablo de Lara Date: Wed, 20 Dec 2023 08:31:05 +0000 Subject: [PATCH] igzip: add zlib header init function Add isal_zlib_hdr_init() function to initialize the isal_zlib_header structure to all 0. Signed-off-by: Pablo de Lara --- igzip/igzip.c | 8 ++++++++ igzip/igzip_inflate.c | 10 ++++++++-- igzip/igzip_wrapper_hdr_test.c | 2 +- include/igzip_lib.h | 7 +++++++ isa-l.def | 1 + 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/igzip/igzip.c b/igzip/igzip.c index 4b4ada6..b1231d4 100644 --- a/igzip/igzip.c +++ b/igzip/igzip.c @@ -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; diff --git a/igzip/igzip_inflate.c b/igzip/igzip_inflate.c index 9e52347..34a9870 100644 --- a/igzip/igzip_inflate.c +++ b/igzip/igzip_inflate.c @@ -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; @@ -2268,6 +2271,7 @@ 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) @@ -2275,7 +2279,9 @@ int isal_inflate(struct inflate_state *state) 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; diff --git a/igzip/igzip_wrapper_hdr_test.c b/igzip/igzip_wrapper_hdr_test.c index 2215251..483a1da 100644 --- a/igzip/igzip_wrapper_hdr_test.c +++ b/igzip/igzip_wrapper_hdr_test.c @@ -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); diff --git a/include/igzip_lib.h b/include/igzip_lib.h index 5733374..439219f 100644 --- a/include/igzip_lib.h +++ b/include/igzip_lib.h @@ -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 * diff --git a/isa-l.def b/isa-l.def index d5ab2ef..05217fe 100644 --- a/isa-l.def +++ b/isa-l.def @@ -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