Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for stupid Xcode 9.2 hard errors? #1

Open
ghost opened this issue Feb 19, 2018 · 5 comments
Open

Workaround for stupid Xcode 9.2 hard errors? #1

ghost opened this issue Feb 19, 2018 · 5 comments

Comments

@ghost
Copy link

ghost commented Feb 19, 2018

In MD5Digest, Xcode 9.2 is flagging these two lines as exceeding the size of a UInt32, which is of course totally wrong:

var b = UInt32(0xefcdab89)
var c = UInt32(0x98badcfe)

Well, I found a workaround (untested at this point):

var b = UInt32(0x70000000) + UInt32(0x7fcdab89) // 0xefcdab89
var c = UInt32(0x40000000) + UInt32(0x58badcfe) // 0x98badcfe

Geez ... [Post is really to help out any other poor soul running into this issue...]

@crrobinson14
Copy link

@dhoerlSA Thanks for posting this. I've tested it and confirmed it works here for the use-cases I'm using this for. Maybe change this to a PR?

@ghost
Copy link
Author

ghost commented Feb 23, 2018 via email

@ghost ghost mentioned this issue Mar 10, 2018
@raymond-liao
Copy link

hi man, you just need change

    var a = UInt32(0x67452301)
    var b = UInt32(0xefcdab89)
    var c = UInt32(0x98badcfe)
    var d = UInt32(0x10325476)

to

    var a: UInt32 = 0x67452301
    var b: UInt32 = 0xefcdab89
    var c: UInt32 = 0x98badcfe
    var d: UInt32 = 0x10325476

all errors should go away.

@cyrille-legrand
Copy link

This workaround works for 64-bit devices, but on 32-bit devices half of the resulting MD5 is filled with zeroes.

On an iPhone X, md5("Hello, world") = bc6e6f16b8a077ef5fbc8d59d0b931b9 ✅
On an iPhone 5, md5("Hello, world") = 00000000b8a077ef00000000bc6e6f16 ❌

Using Xcode 9.4 beta (9Q1004a), iOS 11.4 SDK — same results on simulator or on device.

@martinr448
Copy link

The problem is in

public var description: String {
    return String(format: "%016lx%016lx",
                  _digest.0.byteSwapped,
                  _digest.1.byteSwapped)
}

because on a 32-bit platform long int is a 32-bit integer. The solution is to use llx formats:

public var description: String {
    return String(format: "%016llx%016llx",
                  _digest.0.byteSwapped,
                  _digest.1.byteSwapped)
}

That should work correctly on 32-bit and 64-bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants