convert: Fix compiler warnings

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 <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2015-10-29 09:35:54 +01:00 committed by mayeut
parent 4ac509182a
commit 7dfcbf9d7b
1 changed files with 10 additions and 12 deletions

View File

@ -558,14 +558,12 @@ struct tga_header
}; };
#endif /* INFORMATION_ONLY */ #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 #ifdef OPJ_BIG_ENDIAN
return (unsigned short)(((val & 0xffU) << 8) | (val >> 8)); val = ((val & 0xffU) << 8) | (val >> 8);
#else
return val;
#endif #endif
return val;
} }
#define TGA_HEADER_SIZE 18 #define TGA_HEADER_SIZE 18
@ -591,17 +589,17 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
id_len = tga[0]; id_len = tga[0];
/*cmap_type = tga[1];*/ /*cmap_type = tga[1];*/
image_type = tga[2]; image_type = tga[2];
/*cmap_index = get_ushort(*(unsigned short*)(&tga[3]));*/ /*cmap_index = get_ushort(&tga[3]);*/
cmap_len = get_ushort(*(unsigned short*)(&tga[5])); cmap_len = get_ushort(&tga[5]);
cmap_entry_size = tga[7]; cmap_entry_size = tga[7];
#if 0 #if 0
x_origin = get_ushort(*(unsigned short*)(&tga[8])); x_origin = get_ushort(&tga[8]);
y_origin = get_ushort(*(unsigned short*)(&tga[10])); y_origin = get_ushort(&tga[10]);
#endif #endif
image_w = get_ushort(*(unsigned short*)(&tga[12])); image_w = get_ushort(&tga[12]);
image_h = get_ushort(*(unsigned short*)(&tga[14])); image_h = get_ushort(&tga[14]);
pixel_depth = tga[16]; pixel_depth = tga[16];
image_desc = tga[17]; image_desc = tga[17];