Skip to content

Fix overflow/underflow detection in join_seconds#354

Open
derekmauro wants to merge 1 commit into
google:masterfrom
derekmauro:b529539419
Open

Fix overflow/underflow detection in join_seconds#354
derekmauro wants to merge 1 commit into
google:masterfrom
derekmauro:b529539419

Conversation

@derekmauro

Copy link
Copy Markdown
Member

Improve the precision of overflow and underflow checks in the join_seconds template function.

  • Use int64_t for intermediate subsecond calculations to prevent premature overflow when the target representation type is small.
  • Refine the underflow check to correctly handle boundary cases near the minimum limit, avoiding unsafe subtraction.
  • Handle cases where the duration denominator is larger than the maximum limit of the representation type.

Fixes #199

Improve the precision of overflow and underflow checks in the
`join_seconds` template function. Specifically:
  - Use `int64_t` for intermediate subsecond calculations to prevent
    premature overflow when the target representation type is small.
  - Refine the underflow check to correctly handle boundary cases near
    the minimum limit, avoiding unsafe subtraction.
  - Handle cases where the duration denominator is larger than the maximum
    limit of the representation type.

Fixes google#199
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.

Detect if include/cctz/time_zone.h:join_seconds() would overflow the output time_point

1 participant