changeset 1134:41a93f9896e3

Avoid an array out of bounds after container clear on Mac.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 07 Sep 2011 00:56:46 +0000
parents 25bea6526ca1
children 6828a01ecf3c
files mac/dw.m
diffstat 1 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Tue Sep 06 19:53:39 2011 +0000
+++ b/mac/dw.m	Wed Sep 07 00:56:46 2011 +0000
@@ -1372,16 +1372,17 @@
     if(tvcols && data)
     {
         int cols = (int)[tvcols count];
-        if(cols)
-        {
-            return [data count] / cols;
+        int total = (int)[data count];
+        if(cols && total)
+        {
+            return total / cols;
         }
     }
     return 0;
 }
 -(id)tableView:(NSTableView *)aTable objectValueForTableColumn:(NSTableColumn *)aCol row:(NSInteger)aRow
 {
-    if(tvcols)
+    if(tvcols && data)
     {
         int z, col = -1;
         int count = (int)[tvcols count];
@@ -1397,8 +1398,11 @@
         if(col != -1)
         {
             int index = (int)(aRow * count) + col;
-            id this = [data objectAtIndex:index];
-            return ([this isKindOfClass:[NSNull class]]) ? nil : this;
+            if(index < [data count])
+            {
+                id this = [data objectAtIndex:index];
+                return ([this isKindOfClass:[NSNull class]]) ? nil : this;
+            }
         }
     }
     return nil;