的iOS 7.1 CommonCrypto库抱怨:隐式转换损失整数precision:“NSUInteger”(unsigned long类型),以CC_LONG(无符号整数) [英] iOS 7.1 CommonCrypto library complains: Implicit conversion loses integer precision: 'NSUInteger' (unsigned long) to CC_LONG (unsigned int)

查看:843
本文介绍了的iOS 7.1 CommonCrypto库抱怨:隐式转换损失整数precision:“NSUInteger”(unsigned long类型),以CC_LONG(无符号整数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到上述错误(所有权),而从文件中做了MD5。我通常可以应付这些类型的这种情况下,32-> 64位转换issues..but,我不知道我应该做的CC_MD5是 CommonCrypto-&GT的一部分; CommonDigest ,图书馆附带iOS7.1。我假设 [inputData长度] 将返回NSUInteger,这其中就有问题,但是我可以简单地垂下从UL到用户界面?我很可能会失去precision如果文件很大。为什么一个库,苹果附带要求 INT 在64位计算能力的语言,比如iOS的?是不是有人忽略了一些东西还是我是真的很愚蠢和错误诊断问题?

I get the above error (in title) whilst doing a MD5 from file.. I can usually cope with these type of 32->64bit conversion issues..but in this case, I do not know what I should do as CC_MD5 is part of CommonCrypto->CommonDigest, a library that ships with iOS7.1. I am assuming [inputData length] is returning NSUInteger and therein lies the issue, however can I simply cast down from UL to UI? I will possibly lose precision if the file is large. Why would a library that Apple ships with require int in a 64 bit capable language such as iOS? Did someone overlook something or am I being really stupid and mis-diagnosing the problem?

- (NSString*) getMD5FromFile:(NSString *)pathToFile {
    unsigned char outputData[CC_MD5_DIGEST_LENGTH];

    NSData *inputData = [[NSData alloc] initWithContentsOfFile:pathToFile];
    CC_MD5([inputData bytes], [inputData length], outputData);
    [inputData release];

    NSMutableString *hash = [[NSMutableString alloc] init];

    for (NSUInteger i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
        [hash appendFormat:@"%02x", outputData[i]];
    }

    return [hash autorelease];
}

从CommonCrypto-> CommonDigest.h:

From CommonCrypto->CommonDigest.h:

extern unsigned char *CC_MD5(const void *data, CC_LONG len, unsigned char *md)

我提交错误报告与苹果(#17256918),但不是有没有办法做到这一点没有错误?

I filed bug report with apple (#17256918) but isn't there a way to do this without the error?

推荐答案

您只需要投 [inputData长度] INT uint32_t的你怀疑。

You simply need to cast [inputData length] to either int or uint32_t as you suspect.

不是太大的类型,你可以使用 UINT32_MAX 检查。这里是一个NSAssert你可以用一个例子。

If you want to assert that number is not too large for type you can use the UINT32_MAXto check. Here is an example on an NSAssert you could use.

    NSAssert([inputData length] < UINT32_MAX, @"too big!");

这篇关于的iOS 7.1 CommonCrypto库抱怨:隐式转换损失整数precision:“NSUInteger”(unsigned long类型),以CC_LONG(无符号整数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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