aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/SPMySQLFramework
diff options
context:
space:
mode:
Diffstat (limited to 'Frameworks/SPMySQLFramework')
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Data Conversion.m19
1 files changed, 15 insertions, 4 deletions
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Data Conversion.m b/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Data Conversion.m
index 357eb53f..0ed8a51e 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Data Conversion.m
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Data Conversion.m
@@ -239,6 +239,17 @@ static inline NSString * _bitStringWithBytes(const char *bytes, NSUInteger lengt
return returnString;
}
+static inline NSString * _convertStringDataSafely(const void *dataBytes, NSUInteger dataLength, NSStringEncoding aStringEncoding)
+{
+ NSString * result = [[[NSString alloc] initWithBytes:dataBytes length:dataLength encoding:aStringEncoding] autorelease];
+
+ if (result == nil) {
+ return [[[NSString alloc] initWithBytes:dataBytes length:dataLength encoding:NSASCIIStringEncoding] autorelease];
+ }
+
+ return result;
+}
+
/**
* Converts stored string data - which may contain nul bytes - to a native
* Objective-C string, using the current class encoding.
@@ -247,9 +258,9 @@ static inline NSString * _convertStringData(const void *dataBytes, NSUInteger da
{
// Fast case - if not using a preview length, or if the data length is shorter, return the requested data.
- if (previewLength == NSNotFound || dataLength <= previewLength) {
- return [[[NSString alloc] initWithBytes:dataBytes length:dataLength encoding:aStringEncoding] autorelease];
- }
+ if (previewLength == NSNotFound || dataLength <= previewLength) {
+ return _convertStringDataSafely(dataBytes, dataLength, aStringEncoding);
+ }
NSUInteger i = 0, characterLength = 0, byteLength = previewLength;
uint16_t continuationStart, continuationEnd;
@@ -394,7 +405,7 @@ static inline NSString * _convertStringData(const void *dataBytes, NSUInteger da
// If returning the full string, use a fast path
if (byteLength >= dataLength) {
- return [[[NSString alloc] initWithBytes:dataBytes length:dataLength encoding:aStringEncoding] autorelease];
+ return _convertStringDataSafely(dataBytes, dataLength, aStringEncoding);
}
// Get a string using the calculated details