[Bf-blender-cvs] [1d9e0c3] master: Fix for BLI_rng_shuffle_array noted by mont29
Campbell Barton
noreply at git.blender.org
Wed Apr 2 01:10:53 CEST 2014
Commit: 1d9e0c373d830daccba40fbb35046005cb84b463
Author: Campbell Barton
Date: Wed Apr 2 10:09:48 2014 +1100
https://developer.blender.org/rB1d9e0c373d830daccba40fbb35046005cb84b463
Fix for BLI_rng_shuffle_array noted by mont29
===================================================================
M source/blender/blenlib/intern/rand.c
===================================================================
diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c
index 75ce860..5d78608 100644
--- a/source/blender/blenlib/intern/rand.c
+++ b/source/blender/blenlib/intern/rand.c
@@ -140,15 +140,13 @@ void BLI_rng_shuffle_array(RNG *rng, void *data, unsigned int elem_size_i, unsig
unsigned int i = elem_tot;
void *temp;
- if (elem_tot == 0) {
+ if (elem_tot <= 1) {
return;
}
temp = malloc(elem_size);
- /* XXX Shouldn't it rather be "while (i--) {" ?
- * Else we have no guaranty first (0) element has a chance to be shuffled... --mont29 */
- while (--i) {
+ while (i--) {
unsigned int j = BLI_rng_get_uint(rng) % elem_tot;
if (i != j) {
void *iElem = (unsigned char *)data + i * elem_size_i;
More information about the Bf-blender-cvs
mailing list