From 2c52512caf6ec10f49038e6884b9c2aea905cc4e Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Mon, 11 Jan 2021 21:42:44 +0200 Subject: [PATCH] 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