diff options
author | rowanbeentje <rowan@beent.je> | 2014-06-16 02:28:25 +0100 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2014-06-16 02:28:25 +0100 |
commit | 690c2fa83a5a3138bf4aa0fa862565c833b72d2a (patch) | |
tree | 799539bb55df6b2c4ff65709fd1add69fcc074ce /Source/SPCopyTable.m | |
parent | ae239070319b0a8cacc8b17cdcb245ce29956759 (diff) | |
download | sequelpro-690c2fa83a5a3138bf4aa0fa862565c833b72d2a.tar.gz sequelpro-690c2fa83a5a3138bf4aa0fa862565c833b72d2a.tar.bz2 sequelpro-690c2fa83a5a3138bf4aa0fa862565c833b72d2a.zip |
Add a safety check within [SPCopyTable shouldUseFieldEditorForRow:column:] for use when loading tables, which may improve Issue #1925 and Issue #1902.
Diffstat (limited to 'Source/SPCopyTable.m')
-rw-r--r-- | Source/SPCopyTable.m | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m index 958dd4d5..8eb33525 100644 --- a/Source/SPCopyTable.m +++ b/Source/SPCopyTable.m @@ -52,6 +52,7 @@ #import "SPDatabaseContentViewDelegate.h" #import <SPMySQL/SPMySQL.h> +#import "pthread.h" NSInteger SPEditMenuCopy = 2001; NSInteger SPEditMenuCopyWithColumns = 2002; @@ -1186,7 +1187,7 @@ static const NSInteger kBlobAsImageFile = 4; * Determine whether to use the sheet for editing; do so if the multipleLineEditingButton is enabled, * or if the column was a blob or a text, or if it contains linebreaks. */ -- (BOOL)shouldUseFieldEditorForRow:(NSUInteger)rowIndex column:(NSUInteger)colIndex +- (BOOL)shouldUseFieldEditorForRow:(NSUInteger)rowIndex column:(NSUInteger)colIndex checkWithLock:(pthread_mutex_t *)dataLock { // Retrieve the column definition NSDictionary *columnDefinition = [[(id <SPDatabaseContentViewDelegate>)[self delegate] dataColumnDefinitions] objectAtIndex:colIndex]; @@ -1203,7 +1204,24 @@ static const NSInteger kBlobAsImageFile = 4; if (isBlob && ![columnType isEqualToString:@"enum"]) return YES; // Otherwise, check the cell value for newlines. - id cellValue = [tableStorage cellDataAtRow:rowIndex column:colIndex]; + id cellValue = nil; + + // If a data lock was supplied, use it and perform additional checks for safety + if (dataLock) { + pthread_mutex_lock(dataLock); + + if (rowIndex < [tableStorage count] && colIndex < [tableStorage columnCount]) { + cellValue = [tableStorage cellDataAtRow:rowIndex column:colIndex]; + } + + pthread_mutex_unlock(dataLock); + + if (!cellValue) return YES; + + // Otherwise grab the value directly + } else { + cellValue = [tableStorage cellDataAtRow:rowIndex column:colIndex]; + } if ([cellValue isKindOfClass:[NSData class]]) { cellValue = [[[NSString alloc] initWithData:cellValue encoding:[mySQLConnection stringEncoding]] autorelease]; |