From 7dfcbf9d7b2cb21b753752c06c504b0620191c2a Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Thu, 29 Oct 2015 09:35:54 +0100 Subject: [PATCH] convert: Fix compiler warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix this and other similar compiler warnings: src/bin/jp2/convert.c: In function ‘tga_readheader’: src/bin/jp2/convert.c:595:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] cmap_len = get_ushort(*(unsigned short*)(&tga[5])); Signed-off-by: Stefan Weil --- src/bin/jp2/convert.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index e3af7ee3..b072218c 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -558,14 +558,12 @@ struct tga_header }; #endif /* INFORMATION_ONLY */ -static unsigned short get_ushort(unsigned short val) { - +static unsigned short get_ushort(unsigned char *data) { + unsigned short val = *(unsigned short *)data; #ifdef OPJ_BIG_ENDIAN - return (unsigned short)(((val & 0xffU) << 8) | (val >> 8)); -#else - return val; + val = ((val & 0xffU) << 8) | (val >> 8); #endif - + return val; } #define TGA_HEADER_SIZE 18 @@ -591,17 +589,17 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel, id_len = tga[0]; /*cmap_type = tga[1];*/ image_type = tga[2]; - /*cmap_index = get_ushort(*(unsigned short*)(&tga[3]));*/ - cmap_len = get_ushort(*(unsigned short*)(&tga[5])); + /*cmap_index = get_ushort(&tga[3]);*/ + cmap_len = get_ushort(&tga[5]); cmap_entry_size = tga[7]; #if 0 - x_origin = get_ushort(*(unsigned short*)(&tga[8])); - y_origin = get_ushort(*(unsigned short*)(&tga[10])); + x_origin = get_ushort(&tga[8]); + y_origin = get_ushort(&tga[10]); #endif - image_w = get_ushort(*(unsigned short*)(&tga[12])); - image_h = get_ushort(*(unsigned short*)(&tga[14])); + image_w = get_ushort(&tga[12]); + image_h = get_ushort(&tga[14]); pixel_depth = tga[16]; image_desc = tga[17];