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
3ecad559
Commit
3ecad559
authored
Mar 02, 2016
by
vitaut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix sign conversion warnings
parent
d929fdeb
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
44 additions
and
28 deletions
+44
-28
cppformat/format.cc
cppformat/format.cc
+19
-3
cppformat/format.h
cppformat/format.h
+2
-2
cppformat/posix.cc
cppformat/posix.cc
+2
-2
cppformat/posix.h
cppformat/posix.h
+2
-1
test/gtest-extra-test.cc
test/gtest-extra-test.cc
+1
-1
test/gtest-extra.cc
test/gtest-extra.cc
+3
-4
test/posix-mock-test.cc
test/posix-mock-test.cc
+3
-4
test/posix-test.cc
test/posix-test.cc
+4
-4
test/printf-test.cc
test/printf-test.cc
+5
-5
test/util-test.cc
test/util-test.cc
+3
-2
No files found.
cppformat/format.cc
View file @
3ecad559
...
...
@@ -362,6 +362,21 @@ class CharConverter : public fmt::internal::ArgVisitor<CharConverter, void> {
arg_
.
int_value
=
static_cast
<
char
>
(
value
);
}
};
// Write the content of w to os.
void
write
(
std
::
ostream
&
os
,
fmt
::
MemoryWriter
&
w
)
{
const
char
*
data
=
w
.
data
();
std
::
size_t
size
=
w
.
size
();
typedef
internal
::
MakeUnsigned
<
std
::
streamsize
>::
Type
UnsignedStreamSize
;
UnsignedStreamSize
max_size
=
internal
::
to_unsigned
((
std
::
numeric_limits
<
std
::
streamsize
>::
max
)());
do
{
UnsignedStreamSize
n
=
size
<=
max_size
?
size
:
max_size
;
os
.
write
(
data
,
static_cast
<
std
::
streamsize
>
(
n
));
data
+=
n
;
size
-=
n
;
}
while
(
size
!=
0
);
}
}
// namespace
namespace
internal
{
...
...
@@ -884,10 +899,11 @@ FMT_FUNC void fmt::print(CStringRef format_str, ArgList args) {
print
(
stdout
,
format_str
,
args
);
}
FMT_FUNC
void
fmt
::
print
(
std
::
ostream
&
os
,
CStringRef
format_str
,
ArgList
args
)
{
FMT_FUNC
void
fmt
::
print
(
std
::
ostream
&
os
,
CStringRef
format_str
,
ArgList
args
)
{
MemoryWriter
w
;
w
.
write
(
format_str
,
args
);
os
.
write
(
w
.
data
(),
w
.
size
()
);
write
(
os
,
w
);
}
FMT_FUNC
void
fmt
::
print_colored
(
Color
c
,
CStringRef
format
,
ArgList
args
)
{
...
...
@@ -908,7 +924,7 @@ FMT_FUNC int fmt::fprintf(std::FILE *f, CStringRef format, ArgList args) {
FMT_FUNC
int
fmt
::
fprintf
(
std
::
ostream
&
os
,
CStringRef
format
,
ArgList
args
)
{
MemoryWriter
w
;
printf
(
w
,
format
,
args
);
os
.
write
(
w
.
data
(),
w
.
size
()
);
write
(
os
,
w
);
return
static_cast
<
int
>
(
w
.
size
());
}
...
...
cppformat/format.h
View file @
3ecad559
...
...
@@ -2021,7 +2021,7 @@ class FormatBuf : public std::basic_streambuf<Char> {
int_type
overflow
(
int_type
ch
=
traits_type
::
eof
())
{
if
(
!
traits_type
::
eq_int_type
(
ch
,
traits_type
::
eof
()))
{
size_t
size
=
this
->
pptr
()
-
start_
;
size_t
size
=
this
->
size
()
;
buffer_
.
resize
(
size
);
buffer_
.
reserve
(
size
*
2
);
...
...
@@ -2033,7 +2033,7 @@ class FormatBuf : public std::basic_streambuf<Char> {
}
size_t
size
()
const
{
return
t
his
->
pptr
()
-
start_
;
return
t
o_unsigned
(
this
->
pptr
()
-
start_
)
;
}
};
}
// namespace internal
...
...
cppformat/posix.cc
View file @
3ecad559
...
...
@@ -173,7 +173,7 @@ std::size_t fmt::File::read(void *buffer, std::size_t count) {
FMT_RETRY
(
result
,
FMT_POSIX_CALL
(
read
(
fd_
,
buffer
,
convert_rwcount
(
count
))));
if
(
result
<
0
)
throw
SystemError
(
errno
,
"cannot read from file"
);
return
result
;
return
internal
::
to_unsigned
(
result
)
;
}
std
::
size_t
fmt
::
File
::
write
(
const
void
*
buffer
,
std
::
size_t
count
)
{
...
...
@@ -181,7 +181,7 @@ std::size_t fmt::File::write(const void *buffer, std::size_t count) {
FMT_RETRY
(
result
,
FMT_POSIX_CALL
(
write
(
fd_
,
buffer
,
convert_rwcount
(
count
))));
if
(
result
<
0
)
throw
SystemError
(
errno
,
"cannot write to file"
);
return
result
;
return
internal
::
to_unsigned
(
result
)
;
}
fmt
::
File
fmt
::
File
::
dup
(
int
fd
)
{
...
...
cppformat/posix.h
View file @
3ecad559
...
...
@@ -305,7 +305,8 @@ class File {
// Closes the file.
void
close
();
// Returns the file size.
// Returns the file size. The size has signed type for consistency with
// stat::st_size.
LongLong
size
()
const
;
// Attempts to read count bytes from the file into the specified buffer.
...
...
test/gtest-extra-test.cc
View file @
3ecad559
...
...
@@ -46,7 +46,7 @@ namespace {
std
::
string
sanitize
(
const
std
::
string
&
s
)
{
std
::
string
result
;
for
(
std
::
string
::
const_iterator
i
=
s
.
begin
(),
end
=
s
.
end
();
i
!=
end
;
++
i
)
result
.
push_back
(
*
i
&
0xff
);
result
.
push_back
(
*
i
&
static_cast
<
char
>
(
0xff
)
);
return
result
;
}
...
...
test/gtest-extra.cc
View file @
3ecad559
...
...
@@ -80,10 +80,10 @@ std::string OutputRedirect::restore_and_read() {
return
content
;
// Already read.
enum
{
BUFFER_SIZE
=
4096
};
char
buffer
[
BUFFER_SIZE
];
std
::
s
treamsize
count
=
0
;
std
::
s
ize_t
count
=
0
;
do
{
count
=
read_end_
.
read
(
buffer
,
BUFFER_SIZE
);
content
.
append
(
buffer
,
static_cast
<
std
::
size_t
>
(
count
)
);
content
.
append
(
buffer
,
count
);
}
while
(
count
!=
0
);
read_end_
.
close
();
return
content
;
...
...
@@ -91,8 +91,7 @@ std::string OutputRedirect::restore_and_read() {
std
::
string
read
(
File
&
f
,
std
::
size_t
count
)
{
std
::
string
buffer
(
count
,
'\0'
);
std
::
streamsize
n
=
0
;
std
::
size_t
offset
=
0
;
std
::
size_t
n
=
0
,
offset
=
0
;
do
{
n
=
f
.
read
(
&
buffer
[
offset
],
count
-
offset
);
// We can't read more than size_t bytes since count has type size_t.
...
...
test/posix-mock-test.cc
View file @
3ecad559
...
...
@@ -277,8 +277,7 @@ TEST(FileTest, Size) {
write_file
(
"test"
,
content
);
File
f
(
"test"
,
File
::
RDONLY
);
EXPECT_GE
(
f
.
size
(),
0
);
fmt
::
ULongLong
file_size
=
f
.
size
();
EXPECT_EQ
(
content
.
size
(),
file_size
);
EXPECT_EQ
(
content
.
size
(),
static_cast
<
fmt
::
ULongLong
>
(
f
.
size
()));
#ifdef _WIN32
fmt
::
MemoryWriter
message
;
fmt
::
internal
::
format_windows_error
(
...
...
@@ -308,7 +307,7 @@ TEST(FileTest, ReadRetry) {
write_end
.
write
(
"test"
,
SIZE
);
write_end
.
close
();
char
buffer
[
SIZE
];
std
::
s
treamsize
count
=
0
;
std
::
s
ize_t
count
=
0
;
EXPECT_RETRY
(
count
=
read_end
.
read
(
buffer
,
SIZE
),
read
,
"cannot read from file"
);
EXPECT_EQ_POSIX
(
static_cast
<
std
::
streamsize
>
(
SIZE
),
count
);
...
...
@@ -318,7 +317,7 @@ TEST(FileTest, WriteRetry) {
File
read_end
,
write_end
;
File
::
pipe
(
read_end
,
write_end
);
enum
{
SIZE
=
4
};
std
::
s
treamsize
count
=
0
;
std
::
s
ize_t
count
=
0
;
EXPECT_RETRY
(
count
=
write_end
.
write
(
"test"
,
SIZE
),
write
,
"cannot write to file"
);
write_end
.
close
();
...
...
test/posix-test.cc
View file @
3ecad559
...
...
@@ -69,7 +69,7 @@ void write(File &f, fmt::StringRef s) {
std
::
size_t
num_chars_left
=
s
.
size
();
const
char
*
ptr
=
s
.
data
();
do
{
std
::
s
treamsize
count
=
f
.
write
(
ptr
,
num_chars_left
);
std
::
s
ize_t
count
=
f
.
write
(
ptr
,
num_chars_left
);
ptr
+=
count
;
// We can't write more than size_t bytes since num_chars_left
// has type size_t.
...
...
@@ -236,20 +236,20 @@ File OpenBufferedFile(int &fd) {
}
TEST
(
FileTest
,
MoveFromTemporaryInCtor
)
{
int
fd
=
0xdead
beef
;
int
fd
=
0xdead
;
File
f
(
OpenBufferedFile
(
fd
));
EXPECT_EQ
(
fd
,
f
.
descriptor
());
}
TEST
(
FileTest
,
MoveFromTemporaryInAssignment
)
{
int
fd
=
0xdead
beef
;
int
fd
=
0xdead
;
File
f
;
f
=
OpenBufferedFile
(
fd
);
EXPECT_EQ
(
fd
,
f
.
descriptor
());
}
TEST
(
FileTest
,
MoveFromTemporaryInAssignmentClosesFile
)
{
int
fd
=
0xdead
beef
;
int
fd
=
0xdead
;
File
f
=
open_file
();
int
old_fd
=
f
.
descriptor
();
f
=
OpenBufferedFile
(
fd
);
...
...
test/printf-test.cc
View file @
3ecad559
...
...
@@ -292,21 +292,21 @@ SPECIALIZE_MAKE_SIGNED(fmt::ULongLong, fmt::LongLong);
// Test length format specifier ``length_spec``.
template
<
typename
T
,
typename
U
>
void
TestLength
(
const
char
*
length_spec
,
U
value
)
{
fmt
::
LongLong
signed_value
=
value
;
fmt
::
ULongLong
unsigned_value
=
value
;
fmt
::
LongLong
signed_value
=
0
;
fmt
::
ULongLong
unsigned_value
=
0
;
// Apply integer promotion to the argument.
fmt
::
ULongLong
max
=
std
::
numeric_limits
<
U
>::
max
();
using
fmt
::
internal
::
check
;
if
(
check
(
max
<=
static_cast
<
unsigned
>
(
std
::
numeric_limits
<
int
>::
max
())))
{
signed_value
=
static_cast
<
int
>
(
value
);
unsigned_value
=
static_cast
<
int
>
(
value
);
unsigned_value
=
static_cast
<
unsigned
>
(
value
);
}
else
if
(
check
(
max
<=
std
::
numeric_limits
<
unsigned
>::
max
()))
{
signed_value
=
static_cast
<
unsigned
>
(
value
);
unsigned_value
=
static_cast
<
unsigned
>
(
value
);
}
using
fmt
::
internal
::
MakeUnsigned
;
if
(
sizeof
(
U
)
<=
sizeof
(
int
)
&&
sizeof
(
int
)
<
sizeof
(
T
))
{
signed_value
=
value
;
signed_value
=
static_cast
<
fmt
::
LongLong
>
(
value
)
;
unsigned_value
=
static_cast
<
typename
MakeUnsigned
<
unsigned
>::
Type
>
(
value
);
}
else
{
signed_value
=
static_cast
<
typename
MakeSigned
<
T
>::
Type
>
(
value
);
...
...
@@ -382,7 +382,7 @@ TEST(PrintfTest, Bool) {
TEST
(
PrintfTest
,
Int
)
{
EXPECT_PRINTF
(
"-42"
,
"%d"
,
-
42
);
EXPECT_PRINTF
(
"-42"
,
"%i"
,
-
42
);
unsigned
u
=
-
42
;
unsigned
u
=
-
42
u
;
EXPECT_PRINTF
(
fmt
::
format
(
"{}"
,
u
),
"%u"
,
-
42
);
EXPECT_PRINTF
(
fmt
::
format
(
"{:o}"
,
u
),
"%o"
,
-
42
);
EXPECT_PRINTF
(
fmt
::
format
(
"{:x}"
,
u
),
"%x"
,
-
42
);
...
...
test/util-test.cc
View file @
3ecad559
...
...
@@ -332,8 +332,9 @@ TEST(MemoryBufferTest, Grow) {
void
grow
(
std
::
size_t
size
)
{
Base
::
grow
(
size
);
}
}
buffer
((
Allocator
(
&
alloc
)));
buffer
.
resize
(
7
);
using
fmt
::
internal
::
to_unsigned
;
for
(
int
i
=
0
;
i
<
7
;
++
i
)
buffer
[
i
]
=
i
*
i
;
buffer
[
to_unsigned
(
i
)
]
=
i
*
i
;
EXPECT_EQ
(
10u
,
buffer
.
capacity
());
int
mem
[
20
];
mem
[
7
]
=
0xdead
;
...
...
@@ -342,7 +343,7 @@ TEST(MemoryBufferTest, Grow) {
EXPECT_EQ
(
20u
,
buffer
.
capacity
());
// Check if size elements have been copied
for
(
int
i
=
0
;
i
<
7
;
++
i
)
EXPECT_EQ
(
i
*
i
,
buffer
[
i
]);
EXPECT_EQ
(
i
*
i
,
buffer
[
to_unsigned
(
i
)
]);
// and no more than that.
EXPECT_EQ
(
0xdead
,
buffer
[
7
]);
EXPECT_CALL
(
alloc
,
deallocate
(
mem
,
20
));
...
...
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