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
7ee287d3
Commit
7ee287d3
authored
Jan 27, 2016
by
vitaut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sign extend arguments of smaller types passed to %ll? (#265)
parent
ae6368c9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
6 deletions
+5
-6
format.cc
format.cc
+3
-4
test/printf-test.cc
test/printf-test.cc
+2
-2
No files found.
format.cc
View file @
7ee287d3
...
@@ -328,11 +328,10 @@ class ArgConverter : public fmt::internal::ArgVisitor<ArgConverter<T>, void> {
...
@@ -328,11 +328,10 @@ class ArgConverter : public fmt::internal::ArgVisitor<ArgConverter<T>, void> {
}
else
{
}
else
{
if
(
is_signed
)
{
if
(
is_signed
)
{
arg_
.
type
=
Arg
::
LONG_LONG
;
arg_
.
type
=
Arg
::
LONG_LONG
;
// Convert value to unsigned type before converting to long long for
// glibc's printf doesn't sign extend arguments of smaller types:
// consistency with glibc's printf even though in general it's UB:
// std::printf("%lld", -42); // prints "4294967254"
// std::printf("%lld", -42); // prints "4294967254"
arg_
.
long_long_value
=
// but we don't have to do the same because it's a UB.
static_cast
<
typename
fmt
::
internal
::
MakeUnsigned
<
U
>::
Type
>
(
value
)
;
arg_
.
long_long_value
=
value
;
}
else
{
}
else
{
arg_
.
type
=
Arg
::
ULONG_LONG
;
arg_
.
type
=
Arg
::
ULONG_LONG
;
arg_
.
ulong_long_value
=
arg_
.
ulong_long_value
=
...
...
test/printf-test.cc
View file @
7ee287d3
...
@@ -306,8 +306,8 @@ void TestLength(const char *length_spec, U value) {
...
@@ -306,8 +306,8 @@ void TestLength(const char *length_spec, U value) {
}
}
using
fmt
::
internal
::
MakeUnsigned
;
using
fmt
::
internal
::
MakeUnsigned
;
if
(
sizeof
(
U
)
<=
sizeof
(
int
)
&&
sizeof
(
int
)
<
sizeof
(
T
))
{
if
(
sizeof
(
U
)
<=
sizeof
(
int
)
&&
sizeof
(
int
)
<
sizeof
(
T
))
{
signed_value
=
unsigned_value
=
signed_value
=
value
;
static_cast
<
typename
MakeUnsigned
<
unsigned
>::
Type
>
(
value
);
unsigned_value
=
static_cast
<
typename
MakeUnsigned
<
unsigned
>::
Type
>
(
value
);
}
else
{
}
else
{
signed_value
=
static_cast
<
typename
MakeSigned
<
T
>::
Type
>
(
value
);
signed_value
=
static_cast
<
typename
MakeSigned
<
T
>::
Type
>
(
value
);
unsigned_value
=
static_cast
<
typename
MakeUnsigned
<
T
>::
Type
>
(
value
);
unsigned_value
=
static_cast
<
typename
MakeUnsigned
<
T
>::
Type
>
(
value
);
...
...
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