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

rust: Use i64 for internal unix timestamps #842

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bdrung
Copy link

@bdrung bdrung commented Sep 5, 2024

pendulum 3.0.0 fails to build on 32-bit armhf:

error: this arithmetic operation will overflow
  --> src/helpers.rs:59:20
   |
59 | seconds += ((146_097 - 10957) * SECS_PER_DAY as usize) as isize;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `135140_usize * 86400_usize`, which would overflow
   |
   = note: `#[deny(arithmetic_overflow)]` on by default

(146_097 - 10957) * SECS_PER_DAY equals 11,676,096,000 which does not fit into 32 bit integers.

Use i64 for the seconds variable while handling with the timestamp. Only convert in to usize once the timestamp is split into its components.

Fixes #784

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code.

Copy link

codspeed-hq bot commented Sep 22, 2024

CodSpeed Performance Report

Merging #842 will not alter performance

Comparing bdrung:32-bit (6f2fcb8) with master (3e3fec6)

Summary

✅ 1 untouched benchmarks

@Secrus
Copy link
Collaborator

Secrus commented Sep 22, 2024

Thank you for your patch. Could you please fix the issues highlighted by the CI? You should be able to reproduce this by running make lint-rust. Thank you

pendulum 3.0.0 fails to build on 32-bit armhf:

```
error: this arithmetic operation will overflow
  --> src/helpers.rs:59:20
   |
59 | seconds += ((146_097 - 10957) * SECS_PER_DAY as usize) as isize;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `135140_usize * 86400_usize`, which would overflow
   |
   = note: `#[deny(arithmetic_overflow)]` on by default
```

`(146_097 - 10957) * SECS_PER_DAY` equals 11,676,096,000 which does not
fit into 32 bit integers.

Use i64 for the seconds variable while handling with the timestamp. Only
convert in to `usize` once the timestamp is split into its components.

Fixes sdispater#784
Ubuntu-Bug: https://bugs.launchpad.net/ubuntu/+source/pendulum/+bug/2079029
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

Successfully merging this pull request may close these issues.

Unable to build pendulum for 32bit
2 participants