From owner-dev-commits-src-main@freebsd.org Mon Jan 11 22:58:00 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id ED6E04E91CE; Mon, 11 Jan 2021 22:58:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DF8Hr6NjJz3JXP; Mon, 11 Jan 2021 22:58:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CE3BE228BD; Mon, 11 Jan 2021 22:58:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10BMw0dB097415; Mon, 11 Jan 2021 22:58:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10BMw08l097414; Mon, 11 Jan 2021 22:58:00 GMT (envelope-from git) Date: Mon, 11 Jan 2021 22:58:00 GMT Message-Id: <202101112258.10BMw08l097414@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Toomas Soome Subject: git: 2c52512caf6e - main - pnglite: should use ntohl MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tsoome X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2c52512caf6ec10f49038e6884b9c2aea905cc4e Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Jan 2021 22:58:01 -0000 The branch main has been updated by tsoome: URL: https://cgit.FreeBSD.org/src/commit/?id=2c52512caf6ec10f49038e6884b9c2aea905cc4e commit 2c52512caf6ec10f49038e6884b9c2aea905cc4e Author: Toomas Soome AuthorDate: 2021-01-11 19:42:44 +0000 Commit: Toomas Soome 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