Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
784e2a7b
Commit
784e2a7b
authored
Dec 23, 2021
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix an overflow when formatting very large durations
parent
fc2a376d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
6 deletions
+7
-6
include/fmt/chrono.h
include/fmt/chrono.h
+7
-6
No files found.
include/fmt/chrono.h
View file @
784e2a7b
...
@@ -1663,15 +1663,16 @@ struct chrono_formatter {
...
@@ -1663,15 +1663,16 @@ struct chrono_formatter {
if
(
std
::
ratio_less
<
typename
subsecond_precision
::
period
,
if
(
std
::
ratio_less
<
typename
subsecond_precision
::
period
,
std
::
chrono
::
seconds
::
period
>::
value
)
{
std
::
chrono
::
seconds
::
period
>::
value
)
{
*
out
++
=
'.'
;
*
out
++
=
'.'
;
// Don't convert long double to integer seconds to avoid overflow.
using
sec
=
conditional_t
<
std
::
is_same
<
typename
Duration
::
rep
,
long
double
>::
value
,
std
::
chrono
::
duration
<
long
double
>
,
std
::
chrono
::
seconds
>
;
auto
fractional
=
detail
::
abs
(
d
)
-
std
::
chrono
::
duration_cast
<
sec
>
(
d
);
const
auto
subseconds
=
const
auto
subseconds
=
std
::
chrono
::
treat_as_floating_point
<
std
::
chrono
::
treat_as_floating_point
<
typename
subsecond_precision
::
rep
>::
value
typename
subsecond_precision
::
rep
>::
value
?
(
detail
::
abs
(
d
)
-
?
fractional
.
count
()
std
::
chrono
::
duration_cast
<
std
::
chrono
::
seconds
>
(
d
))
:
std
::
chrono
::
duration_cast
<
subsecond_precision
>
(
fractional
)
.
count
()
:
std
::
chrono
::
duration_cast
<
subsecond_precision
>
(
detail
::
abs
(
d
)
-
std
::
chrono
::
duration_cast
<
std
::
chrono
::
seconds
>
(
d
))
.
count
();
.
count
();
uint32_or_64_or_128_t
<
long
long
>
n
=
uint32_or_64_or_128_t
<
long
long
>
n
=
to_unsigned
(
to_nonnegative_int
(
subseconds
,
max_value
<
long
long
>
()));
to_unsigned
(
to_nonnegative_int
(
subseconds
,
max_value
<
long
long
>
()));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment