Skip to content

Commit 0a2f79c

Browse files
committed
I have a feeling there might be a race condition lurking around here…
1 parent 7335464 commit 0a2f79c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Source/SPDataStorage.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#import "SPDataStorage.h"
3232
#import "SPObjectAdditions.h"
3333
#import <SPMySQL/SPMySQLStreamingResultStore.h>
34+
#include <stdlib.h>
3435

3536
@interface SPDataStorage (Private_API)
3637

@@ -80,7 +81,7 @@ - (void) setDataStorage:(SPMySQLStreamingResultStore *)newDataStorage updatingEx
8081
[self resultStoreDidFinishLoadingData:dataStorage];
8182
}
8283

83-
unloadedColumns = malloc(numberOfColumns * sizeof(BOOL));
84+
unloadedColumns = calloc(numberOfColumns, sizeof(BOOL));
8485
for (i = 0; i < numberOfColumns; i++) {
8586
unloadedColumns[i] = NO;
8687
}
@@ -110,6 +111,7 @@ - (NSMutableArray *) rowContentsAtIndex:(NSUInteger)anIndex
110111

111112
// Modify unloaded cells as appropriate
112113
for (NSUInteger i = 0; i < numberOfColumns; i++) {
114+
NSAssert(unloadedColumns != NULL, @"unloadedColumns not loaded!");
113115
if (unloadedColumns[i]) {
114116
CFArraySetValueAtIndex((CFMutableArrayRef)dataArray, i, [SPNotLoaded notLoaded]);
115117
}
@@ -138,6 +140,7 @@ - (id) cellDataAtRow:(NSUInteger)rowIndex column:(NSUInteger)columnIndex
138140
}
139141

140142
// If the specified column is not loaded, return a SPNotLoaded reference
143+
NSAssert(unloadedColumns != NULL, @"unloadedColumns not loaded!");
141144
if (unloadedColumns[columnIndex]) {
142145
return [SPNotLoaded notLoaded];
143146
}
@@ -172,6 +175,7 @@ - (id) cellPreviewAtRow:(NSUInteger)rowIndex column:(NSUInteger)columnIndex prev
172175
}
173176

174177
// If the specified column is not loaded, return a SPNotLoaded reference
178+
NSAssert(unloadedColumns != NULL, @"unloadedColumns not loaded!");
175179
if (unloadedColumns[columnIndex]) {
176180
return [SPNotLoaded notLoaded];
177181
}
@@ -199,6 +203,7 @@ - (BOOL) cellIsNullOrUnloadedAtRow:(NSUInteger)rowIndex column:(NSUInteger)colum
199203
[NSException raise:NSRangeException format:@"Requested storage column (col %llu) beyond bounds (%llu)", (unsigned long long)columnIndex, (unsigned long long)numberOfColumns];
200204
}
201205

206+
NSAssert(unloadedColumns != NULL, @"unloadedColumns not loaded!");
202207
if (unloadedColumns[columnIndex]) {
203208
return YES;
204209
}
@@ -232,6 +237,7 @@ - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state object
232237

233238
// Modify unloaded cells as appropriate
234239
for (NSUInteger i = 0; i < numberOfColumns; i++) {
240+
NSAssert(unloadedColumns != NULL, @"unloadedColumns not loaded!");
235241
if (unloadedColumns[i]) {
236242
CFArraySetValueAtIndex((CFMutableArrayRef)targetRow, i, [SPNotLoaded notLoaded]);
237243
}
@@ -391,6 +397,7 @@ - (void) setColumnAsUnloaded:(NSUInteger)columnIndex
391397
if (columnIndex >= numberOfColumns) {
392398
[NSException raise:NSRangeException format:@"Invalid column set as unloaded; requested column index (%llu) beyond bounds (%llu)", (unsigned long long)columnIndex, (unsigned long long)numberOfColumns];
393399
}
400+
NSAssert(unloadedColumns != NULL, @"unloadedColumns not loaded!");
394401
unloadedColumns[columnIndex] = YES;
395402
}
396403

0 commit comments

Comments
 (0)