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
a23d5924
Commit
a23d5924
authored
Nov 03, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix check_format_string (#925)
parent
36161284
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
11 deletions
+21
-11
include/fmt/format.h
include/fmt/format.h
+3
-3
test/format-test.cc
test/format-test.cc
+9
-8
test/printf-test.cc
test/printf-test.cc
+9
-0
No files found.
include/fmt/format.h
View file @
a23d5924
...
@@ -2243,7 +2243,7 @@ class format_string_checker {
...
@@ -2243,7 +2243,7 @@ class format_string_checker {
};
};
template
<
typename
Char
,
typename
ErrorHandler
,
typename
...
Args
>
template
<
typename
Char
,
typename
ErrorHandler
,
typename
...
Args
>
FMT_CONSTEXPR
bool
check_format_string
(
FMT_CONSTEXPR
bool
do_
check_format_string
(
basic_string_view
<
Char
>
s
,
ErrorHandler
eh
=
ErrorHandler
())
{
basic_string_view
<
Char
>
s
,
ErrorHandler
eh
=
ErrorHandler
())
{
format_string_checker
<
Char
,
ErrorHandler
,
Args
...
>
checker
(
s
,
eh
);
format_string_checker
<
Char
,
ErrorHandler
,
Args
...
>
checker
(
s
,
eh
);
parse_format_string
<
true
>
(
s
,
checker
);
parse_format_string
<
true
>
(
s
,
checker
);
...
@@ -2254,7 +2254,7 @@ template <typename... Args, typename S>
...
@@ -2254,7 +2254,7 @@ template <typename... Args, typename S>
typename
std
::
enable_if
<
is_compile_string
<
S
>::
value
>::
type
typename
std
::
enable_if
<
is_compile_string
<
S
>::
value
>::
type
check_format_string
(
S
format_str
)
{
check_format_string
(
S
format_str
)
{
typedef
typename
S
::
char_type
char_t
;
typedef
typename
S
::
char_type
char_t
;
FMT_CONSTEXPR_DECL
bool
invalid_format
=
internal
::
check_format_string
<
FMT_CONSTEXPR_DECL
bool
invalid_format
=
internal
::
do_
check_format_string
<
char_t
,
internal
::
error_handler
,
Args
...
>
(
to_string_view
(
format_str
));
char_t
,
internal
::
error_handler
,
Args
...
>
(
to_string_view
(
format_str
));
(
void
)
invalid_format
;
(
void
)
invalid_format
;
}
}
...
@@ -3583,7 +3583,7 @@ class udl_formatter {
...
@@ -3583,7 +3583,7 @@ class udl_formatter {
std
::
basic_string
<
Char
>
operator
()(
const
Args
&
...
args
)
const
{
std
::
basic_string
<
Char
>
operator
()(
const
Args
&
...
args
)
const
{
FMT_CONSTEXPR_DECL
Char
s
[]
=
{
CHARS
...,
'\0'
};
FMT_CONSTEXPR_DECL
Char
s
[]
=
{
CHARS
...,
'\0'
};
FMT_CONSTEXPR_DECL
bool
invalid_format
=
FMT_CONSTEXPR_DECL
bool
invalid_format
=
check_format_string
<
Char
,
error_handler
,
Args
...
>
(
do_
check_format_string
<
Char
,
error_handler
,
Args
...
>
(
basic_string_view
<
Char
>
(
s
,
sizeof
...(
CHARS
)));
basic_string_view
<
Char
>
(
s
,
sizeof
...(
CHARS
)));
(
void
)
invalid_format
;
(
void
)
invalid_format
;
return
format
(
s
,
args
...);
return
format
(
s
,
args
...);
...
...
test/format-test.cc
View file @
a23d5924
...
@@ -1426,13 +1426,14 @@ TEST(FormatterTest, FormatFloat) {
...
@@ -1426,13 +1426,14 @@ TEST(FormatterTest, FormatFloat) {
TEST
(
FormatterTest
,
FormatDouble
)
{
TEST
(
FormatterTest
,
FormatDouble
)
{
check_unknown_types
(
1.2
,
"eEfFgGaA"
,
"double"
);
check_unknown_types
(
1.2
,
"eEfFgGaA"
,
"double"
);
EXPECT_EQ
(
"0"
,
format
(
"{0:}"
,
0.0
));
EXPECT_EQ
(
"0"
,
format
(
"{:}"
,
0.0
));
EXPECT_EQ
(
"0.000000"
,
format
(
"{0:f}"
,
0.0
));
EXPECT_EQ
(
"0.000000"
,
format
(
"{:f}"
,
0.0
));
EXPECT_EQ
(
"392.65"
,
format
(
"{0:}"
,
392.65
));
EXPECT_EQ
(
"0"
,
format
(
"{:g}"
,
0.0
));
EXPECT_EQ
(
"392.65"
,
format
(
"{0:g}"
,
392.65
));
EXPECT_EQ
(
"392.65"
,
format
(
"{:}"
,
392.65
));
EXPECT_EQ
(
"392.65"
,
format
(
"{0:G}"
,
392.65
));
EXPECT_EQ
(
"392.65"
,
format
(
"{:g}"
,
392.65
));
EXPECT_EQ
(
"392.650000"
,
format
(
"{0:f}"
,
392.65
));
EXPECT_EQ
(
"392.65"
,
format
(
"{:G}"
,
392.65
));
EXPECT_EQ
(
"392.650000"
,
format
(
"{0:F}"
,
392.65
));
EXPECT_EQ
(
"392.650000"
,
format
(
"{:f}"
,
392.65
));
EXPECT_EQ
(
"392.650000"
,
format
(
"{:F}"
,
392.65
));
char
buffer
[
BUFFER_SIZE
];
char
buffer
[
BUFFER_SIZE
];
safe_sprintf
(
buffer
,
"%e"
,
392.65
);
safe_sprintf
(
buffer
,
"%e"
,
392.65
);
EXPECT_EQ
(
buffer
,
format
(
"{0:e}"
,
392.65
));
EXPECT_EQ
(
buffer
,
format
(
"{0:e}"
,
392.65
));
...
@@ -2315,7 +2316,7 @@ FMT_CONSTEXPR bool equal(const char *s1, const char *s2) {
...
@@ -2315,7 +2316,7 @@ FMT_CONSTEXPR bool equal(const char *s1, const char *s2) {
template
<
typename
...
Args
>
template
<
typename
...
Args
>
FMT_CONSTEXPR
bool
test_error
(
const
char
*
fmt
,
const
char
*
expected_error
)
{
FMT_CONSTEXPR
bool
test_error
(
const
char
*
fmt
,
const
char
*
expected_error
)
{
const
char
*
actual_error
=
FMT_NULL
;
const
char
*
actual_error
=
FMT_NULL
;
fmt
::
internal
::
check_format_string
<
char
,
test_error_handler
,
Args
...
>
(
fmt
::
internal
::
do_
check_format_string
<
char
,
test_error_handler
,
Args
...
>
(
string_view
(
fmt
,
len
(
fmt
)),
test_error_handler
(
actual_error
));
string_view
(
fmt
,
len
(
fmt
)),
test_error_handler
(
actual_error
));
return
equal
(
actual_error
,
expected_error
);
return
equal
(
actual_error
,
expected_error
);
}
}
...
...
test/printf-test.cc
View file @
a23d5924
...
@@ -509,3 +509,12 @@ TEST(PrintfTest, VPrintf) {
...
@@ -509,3 +509,12 @@ TEST(PrintfTest, VPrintf) {
EXPECT_WRITE
(
stdout
,
fmt
::
vfprintf
(
stdout
,
"%d"
,
args
),
"42"
);
EXPECT_WRITE
(
stdout
,
fmt
::
vfprintf
(
stdout
,
"%d"
,
args
),
"42"
);
EXPECT_WRITE
(
stdout
,
fmt
::
vfprintf
(
std
::
cout
,
"%d"
,
args
),
"42"
);
EXPECT_WRITE
(
stdout
,
fmt
::
vfprintf
(
std
::
cout
,
"%d"
,
args
),
"42"
);
}
}
template
<
typename
...
Args
>
void
check_format_string_regression
(
fmt
::
string_view
s
,
const
Args
&
...
args
)
{
fmt
::
sprintf
(
s
,
args
...);
}
TEST
(
PrintfTest
,
CheckFormatStringRegression
)
{
check_format_string_regression
(
"%c%s"
,
'x'
,
""
);
}
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