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

Explicit convert UINT64_MAX to unsigned #217

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Tests/ObjCTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ static void checkIt(id obj, const char* json) {
checkIt(@123456789, "123456789");
checkIt(@123456789012, "123456789012");
checkIt(@(INT64_MAX), "9223372036854775807");
checkIt(@(UINT64_MAX), "18446744073709551615");
// checkIt(@(UINT64_MAX), "18446744073709551615");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay. I was waving between whether to remove it.

// The above may fail to turn UINT64_MAX to unsigned. In the following,
// we apply an explicit conversion
checkIt(@([@UINT64_MAX unsignedLongLongValue]), "18446744073709551615");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessarily convoluted. You create an NSNumber, turn it back into a native number, then create another NSNumber from that.
It would be much simpler to write [NSNumber numberWithUnsignedLongLong: UINT64_MAX].
Or else @((unsigned long long)UINT64_MAX)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the advice. This is test code and won't be in the product. I will change when ported the the master branch.

}

TEST_CASE("Obj-C Floats", "[Encoder]") {
Expand Down
Loading