From d7871914acd2ed77f43344e36e08944524a67d9e Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Mon, 16 Jan 2017 00:10:38 +0100 Subject: Fix dangerous casts On Windows 64-bit, the size of long is 32-bit, thus any pointer to long cast is not valid. In any case, one should use intptr_t and ptrdiff_t when casting to integers. This commit attempts to fix all instances reported by GCC. When relevant, I replaced code by the macros PTR_ADD, ALIGN_UP from system.h Change-Id: I2273b0e8465d3c4689824717ed5afa5ed238a2dc --- lib/rbcodec/codecs/liba52/bitstream.c | 2 +- lib/rbcodec/codecs/libtremor/codebook.c | 6 +++--- lib/rbcodec/metadata/id3tags.c | 6 +++--- lib/tlsf/src/tlsf.c | 7 ++++--- 4 files changed, 11 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/rbcodec/codecs/liba52/bitstream.c b/lib/rbcodec/codecs/liba52/bitstream.c index 155368f1ed..69dd1dc5b7 100644 --- a/lib/rbcodec/codecs/liba52/bitstream.c +++ b/lib/rbcodec/codecs/liba52/bitstream.c @@ -35,7 +35,7 @@ void a52_bitstream_set_ptr (a52_state_t * state, uint8_t * buf) { int align; - align = (long)buf & 3; + align = (intptr_t)buf & 3; state->buffer_start = (uint32_t *) (buf - align); state->bits_left = 0; state->current_word = 0; diff --git a/lib/rbcodec/codecs/libtremor/codebook.c b/lib/rbcodec/codecs/libtremor/codebook.c index 7087f0a323..f3ac5a2b7e 100644 --- a/lib/rbcodec/codecs/libtremor/codebook.c +++ b/lib/rbcodec/codecs/libtremor/codebook.c @@ -293,7 +293,7 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b, if(b->endbyte < b->storage - 8) { ogg_uint32_t *ptr; unsigned long bit, bitend; - unsigned long adr; + intptr_t adr; ogg_uint32_t cache = 0; int cachesize = 0; const unsigned int cachemask = (1<dec_firsttablen)-1; @@ -303,7 +303,7 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b, const ogg_uint32_t *book_codelist = book->codelist; const char *book_dec_codelengths = book->dec_codelengths; - adr = (unsigned long)b->ptr; + adr = (intptr_t)b->ptr; bit = (adr&3)*8+b->endbit; ptr = (ogg_uint32_t*)(adr&~3); bitend = ((adr&3)+(b->storage-b->endbyte))*8; @@ -334,7 +334,7 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b, cache >>= l; } - adr=(unsigned long)b->ptr; + adr=(intptr_t)b->ptr; bit-=(adr&3)*8+cachesize; b->endbyte+=bit/8; b->ptr+=bit/8; diff --git a/lib/rbcodec/metadata/id3tags.c b/lib/rbcodec/metadata/id3tags.c index 3492197c40..cda8ce3b7a 100644 --- a/lib/rbcodec/metadata/id3tags.c +++ b/lib/rbcodec/metadata/id3tags.c @@ -191,7 +191,7 @@ static int unsynchronize(char* tag, int len, bool *ff_found) wp++; } } - return (long)wp - (long)tag; + return (intptr_t)wp - (intptr_t)tag; } static int unsynchronize_frame(char* tag, int len) @@ -562,7 +562,7 @@ static int unicode_munge(char* string, char* utf8buf, int *len) { (*len)--; utf8 = iso_decode(str, utf8, -1, *len); *utf8 = 0; - *len = (unsigned long)utf8 - (unsigned long)utf8buf; + *len = (intptr_t)utf8 - (intptr_t)utf8buf; break; case 0x01: /* Unicode with or without BOM */ @@ -619,7 +619,7 @@ static int unicode_munge(char* string, char* utf8buf, int *len) { default: /* Plain old string */ utf8 = iso_decode(str, utf8, -1, *len); *utf8 = 0; - *len = (unsigned long)utf8 - (unsigned long)utf8buf; + *len = (intptr_t)utf8 - (intptr_t)utf8buf; break; } return 0; diff --git a/lib/tlsf/src/tlsf.c b/lib/tlsf/src/tlsf.c index 6866f0c9b0..136c4152c0 100644 --- a/lib/tlsf/src/tlsf.c +++ b/lib/tlsf/src/tlsf.c @@ -54,6 +54,7 @@ #include #include +#include #ifndef TLSF_USE_LOCKS #define TLSF_USE_LOCKS (0) @@ -462,7 +463,7 @@ size_t init_memory_pool(size_t mem_pool_size, void *mem_pool) return -1; } - if (((unsigned long) mem_pool & PTR_MASK)) { + if (((intptr_t) mem_pool & PTR_MASK)) { ERROR_MSG("init_memory_pool (): mem_pool must be aligned to a word\n"); return -1; } @@ -522,7 +523,7 @@ size_t add_new_area(void *area, size_t area_size, void *mem_pool) lb1 = ptr->end; /* Merging the new area with the next physically contigous one */ - if ((unsigned long) ib1 == (unsigned long) lb0 + BHDR_OVERHEAD) { + if ((uintptr_t) ib1 == (uintptr_t) lb0 + BHDR_OVERHEAD) { if (tlsf->area_head == ptr) { tlsf->area_head = ptr->next; ptr = ptr->next; @@ -543,7 +544,7 @@ size_t add_new_area(void *area, size_t area_size, void *mem_pool) /* Merging the new area with the previous physically contigous one */ - if ((unsigned long) lb1->ptr.buffer == (unsigned long) ib0) { + if ((intptr_t) lb1->ptr.buffer == (intptr_t) ib0) { if (tlsf->area_head == ptr) { tlsf->area_head = ptr->next; ptr = ptr->next; -- cgit v1.2.3