stringByReplacingOccurrencesOfString 中的随机 malloc 崩溃

发布于 2024-09-19 01:44:28 字数 1460 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

錯遇了你 2024-09-26 01:44:28

我确实相信你的 encryptString 应该是 NSMutableString。

I do believe your encryptString should be NSMutableString.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文