我在stringByReplacingOccurrencesOfString中遇到随机的malloc崩溃。我注意到它在较长的琴弦上崩溃,但我似乎无法找到原因。可能是什么问题?
错误:
CashTrader(53448,0xb0103000) malloc: *** error for object 0x5c5eca0: incorrect checksum for freed object - object was probably modified after being freed.
输入encryptedparams
raStwjnw9uiOEHzF00UazOUp879zUuLwJ6J300BH2DMH29Pww/4mOR3oHXv4F/CL
示例代码:
-(NSURL *)createReqUrl:(NSString *)hostString secure:(BOOL)usessl urlRoot:(NSString*)urlRoot encryptedParam:(NSString *)encryptedparams{
NSString *encryptString;
encryptString = nil;
encryptString = [encryptedparams stringByReplacingOccurrencesOfString:@"+" withString:@"%%2b"];
encryptString = [encryptString stringByReplacingOccurrencesOfString:@"/" withString:@"%%2f"];
encryptString = [encryptString stringByReplacingOccurrencesOfString:@"=" withString:@"%%3d"];
encryptString = [encryptString stringByReplacingOccurrencesOfString:@"@" withString:@"%%40"];
NSString *answer = [[NSString alloc] initWithString:urlRoot];
answer = [[answer stringByAppendingString:encryptString] stringByReplacingOccurrencesOfString:@"%%" withString:@"%"];
NSString *scheme = nil;
if (usessl)
scheme = @"https://";
else
scheme = @"http://";
return [[NSURL alloc] initWithString:[[scheme stringByAppendingString:hostString] stringByAppendingString:answer]];;
}
答案 0 :(得分:1)
我相信你的encryptString应该是NSMutableString。