Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Jan 2021 22:58:00 GMT
From:      Toomas Soome <tsoome@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 2c52512caf6e - main - pnglite: should use ntohl
Message-ID:  <202101112258.10BMw08l097414@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by tsoome:

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

commit 2c52512caf6ec10f49038e6884b9c2aea905cc4e
Author:     Toomas Soome <tsoome@FreeBSD.org>
AuthorDate: 2021-01-11 19:42:44 +0000
Commit:     Toomas Soome <tsoome@FreeBSD.org>
CommitDate: 2021-01-11 22:56:35 +0000

    pnglite: should use ntohl
    
    Replace manual conversion with ntohl()
---
 contrib/pnglite/pnglite.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/contrib/pnglite/pnglite.c b/contrib/pnglite/pnglite.c
index e3cc2f866c6f..f517b6bdcaa5 100644
--- a/contrib/pnglite/pnglite.c
+++ b/contrib/pnglite/pnglite.c
@@ -52,12 +52,12 @@ file_read(png_t *png, void *out, size_t size, size_t numel)
 static int
 file_read_ul(png_t *png, unsigned *out)
 {
-	uint8_t buf[4];
+	uint32_t buf;
 
-	if (file_read(png, buf, 1, 4) != 4)
+	if (file_read(png, &buf, 1, 4) != 4)
 		return (PNG_FILE_ERROR);
 
-	*out = (buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3];
+	*out = ntohl(buf);
 
 	return (PNG_NO_ERROR);
 }
@@ -65,14 +65,7 @@ file_read_ul(png_t *png, unsigned *out)
 static unsigned
 get_ul(uint8_t *buf)
 {
-	unsigned result;
-	uint8_t foo[4];
-
-	memcpy(foo, buf, 4);
-
-	result = (foo[0]<<24) | (foo[1]<<16) | (foo[2]<<8) | foo[3];
-
-	return (result);
+	return (ntohl(*(uint32_t *)buf));
 }
 
 static int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101112258.10BMw08l097414>