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

DDRange fails around UINT64_MAX #135

Open
kenthumphries opened this issue Apr 18, 2015 · 0 comments
Open

DDRange fails around UINT64_MAX #135

kenthumphries opened this issue Apr 18, 2015 · 0 comments

Comments

@kenthumphries
Copy link

Busy writing simple tests as part of the CocoaPods Test Jam!

Created the following test:

- (void)testLocationInRangeMax
{
    UInt64 midLocation = UINT64_MAX / 2;
    UInt64 maxLength = UINT64_MAX;
    DDRange maxRange = DDMakeRange(midLocation, maxLength);

    XCTAssertFalse(DDLocationInRange(midLocation + maxLength + 1, maxRange));
    XCTAssertTrue(DDLocationInRange(midLocation, maxRange));
    XCTAssertFalse(DDLocationInRange(midLocation - 1, maxRange));
    XCTAssertFalse(DDLocationInRange(midLocation - 2, maxRange));
}

The first and last assertions will fail.

The third assertion passes only by chance.

 => DDLocationInRange(midLocation - 1, maxRange)
 => loc - range.location < range.length
 => midLocation -1 - midLocation < maxLength
 => (UINT64_MAX / 2) - 1 - (UINT64_MAX / 2) < UINT64_MAX
 => -1 < range.length
 => UINT64_MAX < UINT64_MAX // Since we're dealing with unsigned ints, -1 wraps back round to UNIT64_MAX
 => Return False

I won't commit this test as it will fail until DDRange is adjusted to take care of UINT64_MAX border cases. :)

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

1 participant