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

Add checks for overflow/underflow in time conversion #2722

Closed
kneth opened this issue May 3, 2016 · 4 comments
Closed

Add checks for overflow/underflow in time conversion #2722

kneth opened this issue May 3, 2016 · 4 comments
Assignees

Comments

@kneth
Copy link
Member

kneth commented May 3, 2016

With the expanded resolution of Date fields, we store dates as (seconds, nanoseconds). Converting to a Date might result in an overflow when seconds > INT64_MAX/1000 (and similar for underflow).

This is not a problem for Realm files used on Android only, but other bindings might be able to utilize the full range i.e., seconds > INT64_MAX/1000.

@cmelchior
Copy link
Contributor

I guess the question is if we should either just accept the overflow or clamp it to Long.MAX_VALUE/Long.MIN_VALUE

E.g List.size() uses Integer.MAX_VALUE for all sizes above that value, but it is arguable an expensive operation to do compared to just accepting whatever overflow there is, and given how little chance there is of this occurring I think I am leaning towards this and just document the behaviour, but what do you think @realm/java ?

@stk1m1
Copy link
Contributor

stk1m1 commented May 4, 2016

I'll investigate this issue as I need to work on #2707. I'll talk with other binding teams if necessary.

@stk1m1 stk1m1 self-assigned this May 4, 2016
@kneth
Copy link
Member Author

kneth commented May 4, 2016

Core has some optimized functions for checking for overflow/underflow.

@stk1m1
Copy link
Contributor

stk1m1 commented May 4, 2016

Thanks @kneth!

I'll make sure to make use/reference out of them.

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

No branches or pull requests

4 participants