相关疑难解决方法(0)

为什么这个Objective-C代码会引发malloc错误?

我用这个方法在object-c中编码base64字符串,但是应用程序有时会崩溃:

- (NSString *) base64Encode
{
    //Point to start of the data and set buffer sizes
    int inLength = [self length];
    int outLength = ((((inLength * 4)/3)/4)*4) + (((inLength * 4)/3)%4 ? 4 : 0);
    const char *inputBuffer = [self bytes];
    char *outputBuffer = malloc(outLength);
    outputBuffer[outLength] = 0;

    //64 digit code
    static char Encode[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

    //start the count
    int cycle = 0;
    int inpos = 0;
    int outpos = 0;
    char temp;

    //Pad the last to bytes, the outbuffer …
Run Code Online (Sandbox Code Playgroud)

c iphone objective-c ios

2
推荐指数
1
解决办法
734
查看次数

标签 统计

c ×1

ios ×1

iphone ×1

objective-c ×1