Author: rfm Date: Mon Sep 26 15:08:55 2016 New Revision: 40110 URL: http://svn.gna.org/viewcvs/gnustep?rev=40110&view=rev Log: avoid sending message with struct return to nil
Modified: libs/webservices/trunk/GWSJSONCoder.m Modified: libs/webservices/trunk/GWSJSONCoder.m URL: http://svn.gna.org/viewcvs/gnustep/libs/webservices/trunk/GWSJSONCoder.m?rev=40110&r1=40109&r2=40110&view=diff ============================================================================== --- libs/webservices/trunk/GWSJSONCoder.m (original) +++ libs/webservices/trunk/GWSJSONCoder.m Mon Sep 26 15:08:55 2016 @@ -270,65 +270,71 @@ else { NSMutableString *m; - NSRange r; m = [NSMutableString alloc]; s = m = [m initWithBytes: ctxt->buffer + start length: ctxt->index - start - 1 encoding: NSUTF8StringEncoding]; - r = NSMakeRange(0, [m length]); - r = [m rangeOfString: @"\\" options: NSLiteralSearch range: r]; - while (r.length > 0) - { - unsigned pos = r.location; - NSString *rep; - - c = [m characterAtIndex: pos + 1]; - if ('u' == c) - { - const char *hex; - unichar u; - - if (pos + 6 > [m length]) - { - ctxt->error = "short unicode escape in string"; - ctxt->index = ctxt->length; - return nil; - } - hex = [[m substringWithRange: NSMakeRange(pos + 2, 4)] - UTF8String]; - if (isxdigit(hex[0]) && isxdigit(hex[1]) - && isxdigit(hex[2]) && isxdigit(hex[3])) - { - u = (unichar) strtol(hex, 0, 16); - } - else - { - ctxt->error = "invalid unicode escape in string"; - ctxt->index = ctxt->length; - return nil; - } - rep = [NSStringClass stringWithCharacters: &u length: 1]; - r.length += 5; - } - else - { - if ('"' == c) rep = @"\""; - else if ('\\' == c) rep = @"\\"; - else if ('b' == c) rep = @"\b"; - else if ('f' == c) rep = @"\f"; - else if ('r' == c) rep = @"\r"; - else if ('n' == c) rep = @"\n"; - else if ('t' == c) rep = @"\t"; - else rep = [NSStringClass stringWithFormat: @"%c", (char)c]; - r.length += 1; - } - [m replaceCharactersInRange: r withString: rep]; - pos++; - r = NSMakeRange(pos, [m length] - pos); - r = [m rangeOfString: @"\\" options: NSLiteralSearch range: r]; - } - } + if (nil != s) + { + NSRange r = NSMakeRange(0, [m length]); + + r = [m rangeOfString: @"\\" options: NSLiteralSearch range: r]; + while (r.length > 0) + { + unsigned pos = r.location; + NSString *rep; + + c = [m characterAtIndex: pos + 1]; + if ('u' == c) + { + const char *hex; + unichar u; + + if (pos + 6 > [m length]) + { + ctxt->error = "short unicode escape in string"; + ctxt->index = ctxt->length; + return nil; + } + hex = [[m substringWithRange: NSMakeRange(pos + 2, 4)] + UTF8String]; + if (isxdigit(hex[0]) && isxdigit(hex[1]) + && isxdigit(hex[2]) && isxdigit(hex[3])) + { + u = (unichar) strtol(hex, 0, 16); + } + else + { + ctxt->error = "invalid unicode escape in string"; + ctxt->index = ctxt->length; + return nil; + } + rep = [NSStringClass stringWithCharacters: &u length: 1]; + r.length += 5; + } + else + { + if ('"' == c) rep = @"\""; + else if ('\\' == c) rep = @"\\"; + else if ('b' == c) rep = @"\b"; + else if ('f' == c) rep = @"\f"; + else if ('r' == c) rep = @"\r"; + else if ('n' == c) rep = @"\n"; + else if ('t' == c) rep = @"\t"; + else rep = [NSStringClass + stringWithFormat: @"%c", (char)c]; + r.length += 1; + } + [m replaceCharactersInRange: r withString: rep]; + pos++; + r = NSMakeRange(pos, [m length] - pos); + r = [m rangeOfString: @"\\" + options: NSLiteralSearch + range: r]; + } + } + } return s; } else if ('[' == c) _______________________________________________ Gnustep-cvs mailing list Gnustep-cvs@gna.org https://mail.gna.org/listinfo/gnustep-cvs