[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37220] branches/soc-2011-onion/source/ blender/blenlib/intern/pbvh.c: Warning fix and some paranoia
Jason Wilkins
Jason.A.Wilkins at gmail.com
Sun Jun 5 21:57:11 CEST 2011
Revision: 37220
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37220
Author: jwilkins
Date: 2011-06-05 19:57:11 +0000 (Sun, 05 Jun 2011)
Log Message:
-----------
Warning fix and some paranoia
map_insert_vert stores vertex indexes in a hash table, it uses the sign to indicate the type of vertex, the original index as unsigned, the conversion to a negative number caused a warning, this fixes it by explicitly casting to int, added an assertion that the index can't be greater than INT_MAX because that would be too big to distinguish it uses sign and it is undefined to cast unsigned to sign if the unsigned number is too big.
TODO: assert technically isn't enough because this check needs to be done in release code, although practically it is actually too much since it is unlikely we will be dealing with 2 billion vertexes any time soon, hence, paranoia
Modified Paths:
--------------
branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c
Modified: branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c 2011-06-05 18:58:22 UTC (rev 37219)
+++ branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c 2011-06-05 19:57:11 UTC (rev 37220)
@@ -350,15 +350,17 @@
if(!BLI_ghash_haskey(map, key)) {
if(BLI_bitmap_get(bvh->vert_bitmap, vertex)) {
- value = SET_INT_IN_POINTER(-(*face_verts) - 1); // XXX: MSVC says, warning C4146: unary minus operator applied to unsigned type, result still unsigned
+ assert(*face_verts < (unsigned)INT_MAX); // results of casting unsigned to signed is undefined
+ value = SET_INT_IN_POINTER(-(int)(*face_verts) - 1);
++(*face_verts);
}
else {
+ assert(*uniq_verts < (unsigned)INT_MAX); // results of casting unsigned to signed is undefined
BLI_bitmap_set(bvh->vert_bitmap, vertex);
- value = SET_INT_IN_POINTER(*uniq_verts);
+ value = SET_INT_IN_POINTER((int)*uniq_verts);
++(*uniq_verts);
}
-
+
BLI_ghash_insert(map, key, value);
return GET_INT_FROM_POINTER(value);
}
More information about the Bf-blender-cvs
mailing list