IOS 7.1 CommonCrypto library complains: implicit conversion loses its whole precision: "NSUInteger" (unsigned long) to CC_LONG (unsigned int)

I get the above error (in the header) when making MD5 from a file. I can usually deal with these types of 32-> 64-bit conversion problems ... but in this case I don’t know what to do, CC_MD5 is part of the CommonCrypto->CommonDigestlibrary that comes with iOS7.1. I suppose [inputData length]NSUInteger is returning, and that is the problem, but can I just drop UL to UI? I may lose accuracy if the file is large. Why is the library that Apple offers requires inta 64-bit language, such as iOS? Did someone miss something or am I really stupid and misdiagnosed 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];
}

CommonCrypt- > CommonDigest.h:

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

apple (# 17256918), ?

+4
2

[inputData length] int uint32_t, .

, , UINT32_MAX . NSAssert.

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

, , . , , :

NSAssert([inputData length] <= (CC_LONG)-1, @"Input length is too big for unsigned CC_LONG type! Or CC_LONG became signed, which is unlikely");

, UINT32_MAX, CC_LONG .

P.S. , (CC_LONG)-1 , , , C, sizeof. , )

0

Source: https://habr.com/ru/post/1544038/


All Articles