[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56550] trunk/blender/source/blender/ blenlib: warn of sign conversions for low level apis - ghash, heap, mempool

Campbell Barton ideasman42 at gmail.com
Wed May 8 14:55:52 CEST 2013


Revision: 56550
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56550
Author:   campbellbarton
Date:     2013-05-08 12:55:51 +0000 (Wed, 08 May 2013)
Log Message:
-----------
warn of sign conversions for low level apis - ghash, heap, mempool

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_ghash.h
    trunk/blender/source/blender/blenlib/intern/BLI_ghash.c
    trunk/blender/source/blender/blenlib/intern/BLI_heap.c
    trunk/blender/source/blender/blenlib/intern/BLI_mempool.c

Modified: trunk/blender/source/blender/blenlib/BLI_ghash.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_ghash.h	2013-05-08 12:55:36 UTC (rev 56549)
+++ trunk/blender/source/blender/blenlib/BLI_ghash.h	2013-05-08 12:55:51 UTC (rev 56550)
@@ -54,7 +54,8 @@
 
 	Entry **buckets;
 	struct BLI_mempool *entrypool;
-	int nbuckets, nentries, cursize;
+	unsigned int nbuckets;
+	unsigned int nentries, cursize;
 } GHash;
 
 typedef struct GHashIterator {

Modified: trunk/blender/source/blender/blenlib/intern/BLI_ghash.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_ghash.c	2013-05-08 12:55:36 UTC (rev 56549)
+++ trunk/blender/source/blender/blenlib/intern/BLI_ghash.c	2013-05-08 12:55:51 UTC (rev 56550)
@@ -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 @@
 
 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 @@
 
 	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 h = 5381;
 
 	for (p = ptr; *p != '\0'; p++) {
-		h = (h << 5) + h + *p;
+		h = (h << 5) + h + (unsigned int)*p;
 	}
 
 	return h;

Modified: trunk/blender/source/blender/blenlib/intern/BLI_heap.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_heap.c	2013-05-08 12:55:36 UTC (rev 56549)
+++ trunk/blender/source/blender/blenlib/intern/BLI_heap.c	2013-05-08 12:55:51 UTC (rev 56550)
@@ -38,6 +38,10 @@
 #include "BLI_memarena.h"
 #include "BLI_heap.h"
 
+#ifdef __GNUC__
+#  pragma GCC diagnostic error "-Wsign-conversion"
+#endif
+
 /***/
 
 struct HeapNode {

Modified: trunk/blender/source/blender/blenlib/intern/BLI_mempool.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_mempool.c	2013-05-08 12:55:36 UTC (rev 56549)
+++ trunk/blender/source/blender/blenlib/intern/BLI_mempool.c	2013-05-08 12:55:51 UTC (rev 56550)
@@ -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 @@
 	}
 
 	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 @@
 
 		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 @@
 
 		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_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_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;
 }




More information about the Bf-blender-cvs mailing list