Correct error in wrapped array-span-iteration
authorCampbell Barton <ideasman42@gmail.com>
Sat, 7 May 2016 13:47:58 +0000 (23:47 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 7 May 2016 13:48:53 +0000 (23:48 +1000)
source/blender/blenlib/intern/array_utils.c

index cbc9b49075fa76a60245652f6fc2731a44b40ae0..5d485e2033deffee1cafe08193660c41b30f28a3 100644 (file)
@@ -196,6 +196,9 @@ bool _bli_array_iter_span(
        if (arr_len == 0) {
                return false;
        }
+       else if (use_wrap && (span_step[0] != arr_len) && (span_step[0] > span_step[1])) {
+               return false;
+       }
 
        const unsigned int arr_stride_uint = (unsigned int)arr_stride;
        const void *item_prev;
@@ -252,7 +255,12 @@ bool _bli_array_iter_span(
                                        }
                                }
 
-                               span_len = (i_step_prev - ((i_step_prev >= i_curr) ? i_curr : (i_curr + arr_len))) + 1;
+                               if (i_step_prev < i_curr) {
+                                       span_len = (i_step_prev + (arr_len - i_curr)) + 1;
+                               }
+                               else {
+                                       span_len = (i_step_prev - i_curr) + 1;
+                               }
                        }
                        else {
                                unsigned int i_step = i_curr + 1;