git: cb17f4a6bdaf - main - kern_ctf: Use zlib's uncompress function for simpler code.

Xin LI delphij at FreeBSD.org
Sun Sep 26 06:34:32 UTC 2021


The branch main has been updated by delphij:

URL: https://cgit.FreeBSD.org/src/commit/?id=cb17f4a6bdaf133bdc658b8ed92ad2c62eff8a18

commit cb17f4a6bdaf133bdc658b8ed92ad2c62eff8a18
Author:     Yoshihiro Ota <ota at j.email.ne.jp>
AuthorDate: 2021-09-26 06:28:43 +0000
Commit:     Xin LI <delphij at FreeBSD.org>
CommitDate: 2021-09-26 06:33:00 +0000

    kern_ctf: Use zlib's uncompress function for simpler code.
    
    Reviewed by:    markj, delphij
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D21531
---
 sys/kern/kern_ctf.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/sys/kern/kern_ctf.c b/sys/kern/kern_ctf.c
index 6a6a08033137..ee7576ab6fb9 100644
--- a/sys/kern/kern_ctf.c
+++ b/sys/kern/kern_ctf.c
@@ -244,7 +244,7 @@ link_elf_ctf_get(linker_file_t lf, linker_ctf_t *lc)
 
 	/* Check if decompression is required. */
 	if (raw != NULL) {
-		z_stream zs;
+		uLongf destlen;
 		int ret;
 
 		/*
@@ -253,22 +253,12 @@ link_elf_ctf_get(linker_file_t lf, linker_ctf_t *lc)
 		 */
 		bcopy(ctf_hdr, ctftab, sizeof(ctf_hdr));
 
-		/* Initialise the zlib structure. */
-		bzero(&zs, sizeof(zs));
-
-		if (inflateInit(&zs) != Z_OK) {
-			error = EIO;
-			goto out;
-		}
-
-		zs.avail_in = shdr[i].sh_size - sizeof(ctf_hdr);
-		zs.next_in = ((uint8_t *) raw) + sizeof(ctf_hdr);
-		zs.avail_out = sz - sizeof(ctf_hdr);
-		zs.next_out = ((uint8_t *) ctftab) + sizeof(ctf_hdr);
-		ret = inflate(&zs, Z_FINISH);
-		inflateEnd(&zs);
-		if (ret != Z_STREAM_END) {
-			printf("%s(%d): zlib inflate returned %d\n", __func__, __LINE__, ret);
+		destlen = sz - sizeof(ctf_hdr);
+		ret = uncompress(((uint8_t *) ctftab) + sizeof(ctf_hdr),
+		    &destlen, ((uint8_t *) raw) + sizeof(ctf_hdr),
+		    shdr[i].sh_size - sizeof(ctf_hdr));
+		if (ret != Z_OK) {
+			printf("%s(%d): zlib uncompress returned %d\n", __func__, __LINE__, ret);
 			error = EIO;
 			goto out;
 		}


More information about the dev-commits-src-main mailing list