stringByReplacingOccurrencesOfString 中的随机 malloc 崩溃
我在 stringByReplacingOccurrencesOfString 中遇到随机 malloc 崩溃。我注意到它在较长的字符串上崩溃,但我似乎找不到原因。可能是什么问题?
错误:
CashTrader(53448,0xb0103000) malloc: *** error for object 0x5c5eca0: incorrect checksum for freed object - object was probably modified after being freed.
输入 cryptoparams
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]];;
}
I am getting random malloc crashes in stringByReplacingOccurrencesOfString. I've noticed that it crashes on longer strings, but I can't seem to find why. What could be the problem?
The error:
CashTrader(53448,0xb0103000) malloc: *** error for object 0x5c5eca0: incorrect checksum for freed object - object was probably modified after being freed.
Input encryptedparams
raStwjnw9uiOEHzF00UazOUp879zUuLwJ6J300BH2DMH29Pww/4mOR3oHXv4F/CL
Sample Code:
-(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]];;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我确实相信你的 encryptString 应该是 NSMutableString。
I do believe your encryptString should be NSMutableString.