diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-05-08 16:55:51 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-05-08 16:55:51 +0400 |
commit | 3b341068ba6be81083644ca56649466ad933fdbb (patch) | |
tree | f704b667f0925699cc3df7cd148145504666f946 /source | |
parent | 89c8de1f48607a5d887b44966be220ed9bf93285 (diff) |
warn of sign conversions for low level apis - ghash, heap, mempool
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/BLI_ghash.h | 3 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash.c | 10 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_heap.c | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_mempool.c | 18 |
4 files changed, 24 insertions, 11 deletions
diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h index 641aaa1f3fc..d54d4d5272b 100644 --- a/source/blender/blenlib/BLI_ghash.h +++ b/source/blender/blenlib/BLI_ghash.h @@ -54,7 +54,8 @@ typedef struct GHash { Entry **buckets; struct BLI_mempool *entrypool; - int nbuckets, nentries, cursize; + unsigned int nbuckets; + unsigned int nentries, cursize; } GHash; typedef struct GHashIterator { diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index 8c73cf8960c..f46643c5d89 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -42,6 +42,10 @@ #include "MEM_sys_types.h" /* for intptr_t support */ /***/ +#ifdef __GNUC__ +# pragma GCC diagnostic error "-Wsign-conversion" +#endif + const unsigned int hashsizes[] = { 5, 11, 17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209, 16411, 32771, 65537, 131101, 262147, 524309, 1048583, 2097169, @@ -69,7 +73,7 @@ GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) int BLI_ghash_size(GHash *gh) { - return gh->nentries; + return (int)gh->nentries; } void BLI_ghash_insert(GHash *gh, void *key, void *val) @@ -84,7 +88,7 @@ void BLI_ghash_insert(GHash *gh, void *key, void *val) if (++gh->nentries > (float)gh->nbuckets / 2) { Entry **old = gh->buckets; - int i, nold = gh->nbuckets; + unsigned int i, nold = gh->nbuckets; gh->nbuckets = hashsizes[++gh->cursize]; gh->buckets = (Entry **)MEM_callocN(gh->nbuckets * sizeof(*gh->buckets), "buckets"); @@ -351,7 +355,7 @@ unsigned int BLI_ghashutil_strhash(const void *ptr) unsigned int h = 5381; for (p = ptr; *p != '\0'; p++) { - h = (h << 5) + h + *p; + h = (h << 5) + h + (unsigned int)*p; } return h; diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c index 53489c76962..a8fdcd56abb 100644 --- a/source/blender/blenlib/intern/BLI_heap.c +++ b/source/blender/blenlib/intern/BLI_heap.c @@ -38,6 +38,10 @@ #include "BLI_memarena.h" #include "BLI_heap.h" +#ifdef __GNUC__ +# pragma GCC diagnostic error "-Wsign-conversion" +#endif + /***/ struct HeapNode { diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index 5f0c90f234d..136ecc244fa 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -43,6 +43,10 @@ #include <string.h> #include <stdlib.h> +#ifdef __GNUC__ +# pragma GCC diagnostic error "-Wsign-conversion" +#endif + /* note: copied from BLO_blend_defs.h, don't use here because we're in BLI */ #ifdef __BIG_ENDIAN__ /* Big Endian */ @@ -103,7 +107,7 @@ BLI_mempool *BLI_mempool_create(int esize, int totelem, int pchunk, int flag) } if (flag & BLI_MEMPOOL_ALLOW_ITER) { - pool->esize = MAX2(esize, sizeof(BLI_freenode)); + pool->esize = MAX2(esize, (int)sizeof(BLI_freenode)); } else { pool->esize = esize; @@ -127,11 +131,11 @@ BLI_mempool *BLI_mempool_create(int esize, int totelem, int pchunk, int flag) if (flag & BLI_MEMPOOL_SYSMALLOC) { mpchunk = malloc(sizeof(BLI_mempool_chunk)); - mpchunk->data = malloc(pool->csize); + mpchunk->data = malloc((size_t)pool->csize); } else { mpchunk = MEM_mallocN(sizeof(BLI_mempool_chunk), "BLI_Mempool Chunk"); - mpchunk->data = MEM_mallocN(pool->csize, "BLI Mempool Chunk Data"); + mpchunk->data = MEM_mallocN((size_t)pool->csize, "BLI Mempool Chunk Data"); } mpchunk->next = mpchunk->prev = NULL; @@ -190,11 +194,11 @@ void *BLI_mempool_alloc(BLI_mempool *pool) if (pool->flag & BLI_MEMPOOL_SYSMALLOC) { mpchunk = malloc(sizeof(BLI_mempool_chunk)); - mpchunk->data = malloc(pool->csize); + mpchunk->data = malloc((size_t)pool->csize); } else { mpchunk = MEM_mallocN(sizeof(BLI_mempool_chunk), "BLI_Mempool Chunk"); - mpchunk->data = MEM_mallocN(pool->csize, "BLI_Mempool Chunk Data"); + mpchunk->data = MEM_mallocN((size_t)pool->csize, "BLI_Mempool Chunk Data"); } mpchunk->next = mpchunk->prev = NULL; @@ -237,7 +241,7 @@ void *BLI_mempool_alloc(BLI_mempool *pool) void *BLI_mempool_calloc(BLI_mempool *pool) { void *retval = BLI_mempool_alloc(pool); - memset(retval, 0, pool->esize); + memset(retval, 0, (size_t)pool->esize); return retval; } @@ -346,7 +350,7 @@ void BLI_mempool_as_array(BLI_mempool *pool, void **data) */ void *BLI_mempool_as_arrayN(BLI_mempool *pool, const char *allocstr) { - void *data = MEM_mallocN(BLI_mempool_count(pool) * pool->esize, allocstr); + void *data = MEM_mallocN((size_t)(BLI_mempool_count(pool) * pool->esize), allocstr); BLI_mempool_as_array(pool, data); return data; } |