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
215f21a0
Commit
215f21a0
authored
Dec 05, 2021
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Detect overflow on large precision
parent
c240d98f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
2 deletions
+10
-2
include/fmt/format-inl.h
include/fmt/format-inl.h
+6
-1
test/format-test.cc
test/format-test.cc
+3
-0
test/fuzzing/float.cc
test/fuzzing/float.cc
+1
-1
No files found.
include/fmt/format-inl.h
View file @
215f21a0
...
@@ -704,7 +704,12 @@ FMT_INLINE FMT_CONSTEXPR20 digits::result grisu_gen_digits(
...
@@ -704,7 +704,12 @@ FMT_INLINE FMT_CONSTEXPR20 digits::result grisu_gen_digits(
if
(
handler
.
fixed
)
{
if
(
handler
.
fixed
)
{
// Adjust fixed precision by exponent because it is relative to decimal
// Adjust fixed precision by exponent because it is relative to decimal
// point.
// point.
handler
.
precision
+=
exp
+
handler
.
exp10
;
int
precision_offset
=
exp
+
handler
.
exp10
;
if
(
precision_offset
>
0
&&
handler
.
precision
>
max_value
<
int
>
()
-
precision_offset
)
{
throw
format_error
(
"number is too big"
);
}
handler
.
precision
+=
precision_offset
;
// Check if precision is satisfied just by leading zeros, e.g.
// Check if precision is satisfied just by leading zeros, e.g.
// format("{:.2f}", 0.001) gives "0.00" without generating any digits.
// format("{:.2f}", 0.001) gives "0.00" without generating any digits.
if
(
handler
.
precision
<=
0
)
{
if
(
handler
.
precision
<=
0
)
{
...
...
test/format-test.cc
View file @
215f21a0
...
@@ -934,6 +934,9 @@ TEST(format_test, precision) {
...
@@ -934,6 +934,9 @@ TEST(format_test, precision) {
EXPECT_THROW_MSG
((
void
)
fmt
::
format
(
runtime
(
"{:.{}e}"
),
42.0
,
EXPECT_THROW_MSG
((
void
)
fmt
::
format
(
runtime
(
"{:.{}e}"
),
42.0
,
fmt
::
detail
::
max_value
<
int
>
()),
fmt
::
detail
::
max_value
<
int
>
()),
format_error
,
"number is too big"
);
format_error
,
"number is too big"
);
EXPECT_THROW_MSG
(
(
void
)
fmt
::
format
(
"{:.2147483646f}"
,
-
2.2121295195081227E+304
),
format_error
,
"number is too big"
);
EXPECT_EQ
(
"st"
,
fmt
::
format
(
"{0:.2}"
,
"str"
));
EXPECT_EQ
(
"st"
,
fmt
::
format
(
"{0:.2}"
,
"str"
));
}
}
...
...
test/fuzzing/float.cc
View file @
215f21a0
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
void
check_round_trip
(
fmt
::
string_view
format_str
,
double
value
)
{
void
check_round_trip
(
fmt
::
string_view
format_str
,
double
value
)
{
auto
buffer
=
fmt
::
memory_buffer
();
auto
buffer
=
fmt
::
memory_buffer
();
fmt
::
format_to
(
buffer
,
format_str
,
value
);
fmt
::
format_to
(
std
::
back_inserter
(
buffer
)
,
format_str
,
value
);
if
(
std
::
isnan
(
value
))
{
if
(
std
::
isnan
(
value
))
{
auto
nan
=
std
::
signbit
(
value
)
?
"-nan"
:
"nan"
;
auto
nan
=
std
::
signbit
(
value
)
?
"-nan"
:
"nan"
;
...
...
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