Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

cpeterso
Copy link
Contributor

Note that Timespec does not perform any range checking and this change does not add any!

This implementation of Ord assumes that pre-epoch Timespecs have negative sec and positive nsec fields. Linux's and Darwin's struct timespec functions handle pre-epoch timestamps with this "two steps back, half step forward" representation, though I cannot find any documentation that actually puts this in writing. This means that (say) -1.2 seconds is represented by Timespec { sec: -2_i64, nsec: 800_000_000_i32 }, not something like Timespec { sec: -1_i64, nsec: -200_000_000_i32 } or Timespec { sec: -1_i64, nsec: 200_000_000_i32 }.

If we wish to codify this implementation detail, we could make Timespec nsec unsigned and add range checks asserting nsec <= 999_999_999_u32. btw, struct Tm also lacks range checking and uses signed integers for fields that can't be negative.

@cpeterso cpeterso closed this Jan 17, 2013
@cpeterso cpeterso reopened this Jan 17, 2013
@cpeterso cpeterso closed this Jan 17, 2013
RalfJung added a commit to RalfJung/rust that referenced this pull request Aug 19, 2025
Use GH app for authenticating pull PRs
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.

4 participants