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
aab84f67
Commit
aab84f67
authored
May 06, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix warnings.
parent
6bd3880c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
33 deletions
+15
-33
test/gtest-extra-test.cc
test/gtest-extra-test.cc
+0
-22
test/gtest-extra.cc
test/gtest-extra.cc
+15
-11
No files found.
test/gtest-extra-test.cc
View file @
aab84f67
...
@@ -504,28 +504,6 @@ TEST(FileTest, Read) {
...
@@ -504,28 +504,6 @@ TEST(FileTest, Read) {
EXPECT_READ
(
f
,
"language: cpp"
);
EXPECT_READ
(
f
,
"language: cpp"
);
}
}
#ifdef _WIN32
// The count argument to the read function is unsigned on Windows, so check
// if integer overflow is handled properly.
TEST
(
FileTest
,
ReadCountOverflow
)
{
if
(
sizeof
(
std
::
size_t
)
==
sizeof
(
unsigned
))
return
;
File
read_end
,
write_end
;
File
::
pipe
(
read_end
,
write_end
);
Write
(
write_end
,
"test"
);
write_end
.
close
();
char
buffer
[
4
];
std
::
size_t
offset
=
0
;
std
::
size_t
count
=
std
::
numeric_limits
<
unsigned
>::
max
()
+
std
::
size_t
(
1
);
std
::
streamsize
n
=
0
;
do
{
n
=
read_end
.
read
(
buffer
+
offset
,
count
);
offset
+=
n
;
}
while
(
n
!=
0
);
EXPECT_EQ
(
"test"
,
std
::
string
(
buffer
,
offset
));
}
#endif
TEST
(
FileTest
,
ReadError
)
{
TEST
(
FileTest
,
ReadError
)
{
File
read_end
,
write_end
;
File
read_end
,
write_end
;
File
::
pipe
(
read_end
,
write_end
);
File
::
pipe
(
read_end
,
write_end
);
...
...
test/gtest-extra.cc
View file @
aab84f67
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
#if FMT_USE_FILE_DESCRIPTORS
#if FMT_USE_FILE_DESCRIPTORS
#include <errno.h>
#include <errno.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
...
@@ -51,6 +52,19 @@
...
@@ -51,6 +52,19 @@
result = (expression); \
result = (expression); \
} while (result == -1 && errno == EINTR)
} while (result == -1 && errno == EINTR)
namespace
{
// TODO: test
#ifdef _WIN32
// On Windows the count argument to read and write is unsigned, so convert
// it from size_t preventing integer overflow.
inline
unsigned
ConvertRWCount
(
std
::
size_t
count
)
{
return
count
<=
UINT_MAX
?
count
:
UINT_MAX
;
}
#else
inline
std
::
size_t
ConvertRWCount
(
std
::
size_t
count
)
{
return
count
;
}
#endif
}
BufferedFile
::~
BufferedFile
()
FMT_NOEXCEPT
(
true
)
{
BufferedFile
::~
BufferedFile
()
FMT_NOEXCEPT
(
true
)
{
if
(
file_
&&
std
::
fclose
(
file_
)
!=
0
)
if
(
file_
&&
std
::
fclose
(
file_
)
!=
0
)
fmt
::
ReportSystemError
(
errno
,
"cannot close file"
);
fmt
::
ReportSystemError
(
errno
,
"cannot close file"
);
...
@@ -102,16 +116,6 @@ void File::close() {
...
@@ -102,16 +116,6 @@ void File::close() {
fmt
::
ThrowSystemError
(
errno
,
"cannot close file"
);
fmt
::
ThrowSystemError
(
errno
,
"cannot close file"
);
}
}
#ifdef _WIN32
// On Windows the count argument to read and write is unsigned, so convert
// it from size_t preventing integer overflow.
inline
unsigned
ConvertRWCount
(
std
::
size_t
count
)
{
return
count
<=
UINT_MAX
?
count
:
UINT_MAX
;
}
#else
inline
std
::
size_t
ConvertRWCount
(
std
::
size_t
count
)
{
return
count
;
}
#endif
std
::
streamsize
File
::
read
(
void
*
buffer
,
std
::
size_t
count
)
{
std
::
streamsize
File
::
read
(
void
*
buffer
,
std
::
size_t
count
)
{
std
::
streamsize
result
=
0
;
std
::
streamsize
result
=
0
;
FMT_RETRY
(
result
,
::
FMT_POSIX
(
read
(
fd_
,
buffer
,
ConvertRWCount
(
count
))));
FMT_RETRY
(
result
,
::
FMT_POSIX
(
read
(
fd_
,
buffer
,
ConvertRWCount
(
count
))));
...
@@ -122,7 +126,7 @@ std::streamsize File::read(void *buffer, std::size_t count) {
...
@@ -122,7 +126,7 @@ std::streamsize File::read(void *buffer, std::size_t count) {
std
::
streamsize
File
::
write
(
const
void
*
buffer
,
std
::
size_t
count
)
{
std
::
streamsize
File
::
write
(
const
void
*
buffer
,
std
::
size_t
count
)
{
std
::
streamsize
result
=
0
;
std
::
streamsize
result
=
0
;
FMT_RETRY
(
result
,
::
FMT_POSIX
(
write
(
fd_
,
buffer
,
count
)));
FMT_RETRY
(
result
,
::
FMT_POSIX
(
write
(
fd_
,
buffer
,
ConvertRWCount
(
count
)
)));
if
(
result
==
-
1
)
if
(
result
==
-
1
)
fmt
::
ThrowSystemError
(
errno
,
"cannot write to file"
);
fmt
::
ThrowSystemError
(
errno
,
"cannot write to file"
);
return
result
;
return
result
;
...
...
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