comparison mac/dw.m @ 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
comparison
equal deleted inserted replaced
1133:25bea6526ca1 1134:41a93f9896e3
1370 -(NSInteger)numberOfRowsInTableView:(NSTableView *)aTable 1370 -(NSInteger)numberOfRowsInTableView:(NSTableView *)aTable
1371 { 1371 {
1372 if(tvcols && data) 1372 if(tvcols && data)
1373 { 1373 {
1374 int cols = (int)[tvcols count]; 1374 int cols = (int)[tvcols count];
1375 if(cols) 1375 int total = (int)[data count];
1376 { 1376 if(cols && total)
1377 return [data count] / cols; 1377 {
1378 return total / cols;
1378 } 1379 }
1379 } 1380 }
1380 return 0; 1381 return 0;
1381 } 1382 }
1382 -(id)tableView:(NSTableView *)aTable objectValueForTableColumn:(NSTableColumn *)aCol row:(NSInteger)aRow 1383 -(id)tableView:(NSTableView *)aTable objectValueForTableColumn:(NSTableColumn *)aCol row:(NSInteger)aRow
1383 { 1384 {
1384 if(tvcols) 1385 if(tvcols && data)
1385 { 1386 {
1386 int z, col = -1; 1387 int z, col = -1;
1387 int count = (int)[tvcols count]; 1388 int count = (int)[tvcols count];
1388 1389
1389 for(z=0;z<count;z++) 1390 for(z=0;z<count;z++)
1395 } 1396 }
1396 } 1397 }
1397 if(col != -1) 1398 if(col != -1)
1398 { 1399 {
1399 int index = (int)(aRow * count) + col; 1400 int index = (int)(aRow * count) + col;
1400 id this = [data objectAtIndex:index]; 1401 if(index < [data count])
1401 return ([this isKindOfClass:[NSNull class]]) ? nil : this; 1402 {
1403 id this = [data objectAtIndex:index];
1404 return ([this isKindOfClass:[NSNull class]]) ? nil : this;
1405 }
1402 } 1406 }
1403 } 1407 }
1404 return nil; 1408 return nil;
1405 } 1409 }
1406 -(BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { return NO; } 1410 -(BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { return NO; }