memcpy的崩溃只在iPhone 5S [英] Memcpy crash only on iPhone 5s

查看:1169
本文介绍了memcpy的崩溃只在iPhone 5S的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有,

我面临着一个奇怪的问题与iPhone 5S。我做了 HMAC-SHA1 加密在我的应用程序中使用第三方库。库使用的memcpy ,这我不知道它是什么,因为我没有考虑太多的记忆水平编程 C 。加密工作完全正常在所有的iPhone除了 64位5S 。下面是code其中崩溃(5号线)

I am facing a strange issue with iPhone 5s. I am doing a HMAC-SHA1 encrypting in my app using a third party library. The library uses memcpy, which am not aware what it is, as I am not into too much of memory level programming in C. The encryption works perfectly fine in all iphones except the 64 bit 5s. Below is the code where it crashes (5th line).

void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len)
{
unsigned int i, j;

    j = (context->count[0] >> 3) & 63;
    if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++;
    context->count[1] += (len >> 29);
    if ((j + len) > 63) {
        memcpy(&context->buffer[j], data, (i = 64-j));
        SHA1Transform(context->state, context->buffer);
        for ( ; i + 63 < len; i += 64) {
            SHA1Transform(context->state, &data[i]);
        }
        j = 0;
    }
    else i = 0;
    memcpy(&context->buffer[j], &data[i], len - i);
}

下面是坠机细节

Below is the crash details

异常类型:EXC_BAD_ACCESS(SIGSEGV)   异常子类型:KERN_INVALID_ADDRESS在0x001a9c799cbfdcf9   通过主题:0触发

Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x001a9c799cbfdcf9 Triggered by Thread: 0

主题0崩溃:   0 libsystem_platform.dylib 0x0000000191c34dc8 _platform_memmove + 40   1 Anyvan 0x00000001001fc6a8 SHA1Update(sha1.c:128)   2 Anyvan 0x00000001000c7efc HMAC_SHA1(hmac.c:73)   3 Anyvan 0x00000001000fe7cc - [LoginViewController callAuth:(LoginViewController.m:360)

Thread 0 Crashed: 0 libsystem_platform.dylib 0x0000000191c34dc8 _platform_memmove + 40 1 Anyvan 0x00000001001fc6a8 SHA1Update (sha1.c:128) 2 Anyvan 0x00000001000c7efc hmac_sha1 (hmac.c:73) 3 Anyvan 0x00000001000fe7cc -[LoginViewController callAuth:] (LoginViewController.m:360)

任何帮助将是非常美联社preciated。

Any help will be highly appreciated.

推荐答案

这是崩溃,因为你使用 INT 不是因为的memcpy 。尝试使用 NSInteger的替换 INT ,它应该工作。你可以找到更多信息<一个href="https://developer.apple.com/library/mac/DOCUMENTATION/Cocoa/Conceptual/Cocoa64BitGuide/Introduction/Introduction.html"相对=nofollow>此处。

This is crashing because you are using int not because of memcpy. Try replacing the int with NSInteger and it should work. You can find more information here.

该iPhone5S采用64位架构,而其他使用32位。一个在两者之间的芯的差异是系统如何处理整数作为在doc说明。您的code使用无符号整型这并不意味着同样的事情在32位和64位上,而导致崩溃。你应该改变你的 INT 名为Ĵ NSIntegers ,我相信你的code会工作。还是来想想看,你可以尝试通过简单地替换词 INT

The iPhone5S uses a 64bit architecture while the others use 32bit. One of the core differences between the two is how the system handles integers as explained in the doc. Your code is using unsigned int which does not mean the same thing on 32bit and on 64bit and that results in a crash. You should change your int called i and j to NSIntegers and I believe your code will work. Or come to think of it you can try to simply replace the word int by long.

这篇关于memcpy的崩溃只在iPhone 5S的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆