aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/SPMySQLFramework
diff options
context:
space:
mode:
authorteng.liu <teng.liu@dianping.com>2015-02-08 18:18:35 +0800
committerteng.liu <teng.liu@dianping.com>2015-02-08 18:18:35 +0800
commitb00142a846ceda985516a0bdec3c1d6a9f47bdee (patch)
treeb83824a044ff8764beaa99c216dd37345b254f58 /Frameworks/SPMySQLFramework
parentb1e32f6583f113c279dcde61f4f531d637118bdd (diff)
downloadsequelpro-b00142a846ceda985516a0bdec3c1d6a9f47bdee.tar.gz
sequelpro-b00142a846ceda985516a0bdec3c1d6a9f47bdee.tar.bz2
sequelpro-b00142a846ceda985516a0bdec3c1d6a9f47bdee.zip
fallback solution for NSString decode error
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