Skip to content

Fix overflow/underflow detection in join_seconds#354

Open
derekmauro wants to merge 2 commits into
google:masterfrom
derekmauro:b529539419
Open

Fix overflow/underflow detection in join_seconds#354
derekmauro wants to merge 2 commits 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

derekmauro and others added 2 commits July 17, 2026 15:52
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
@devbww

devbww commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

@derekmauro ... Just a heads-up that I think I'll have some comments for this, but it might take me a day or two to formulate them. Thanks.

@derekmauro

Copy link
Copy Markdown
Member Author

@devbww - No problem. If you haven't figured it out yet, thanks to Mythos we are all inundated with bugs, and apparently I am not the only person with access. Take your time.

@devbww

devbww commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

If you haven't figured it out yet, thanks to Mythos we are all inundated with bugs, and apparently I am not the only person with access.

I had not figured it out, but I was beginning to wonder. Hopefully the pickings are getting slimmer. :-)

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

2 participants