You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2016/09/29 00:49:46 UTC
[3/3] mesos git commit: Windows: Fixed warnings in `read` and `write`
functions.
Windows: Fixed warnings in `read` and `write` functions.
Addresses some implicit casting from signed to/from unsigned values.
Review: https://reviews.apache.org/r/52196/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9bb43bab
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9bb43bab
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9bb43bab
Branch: refs/heads/master
Commit: 9bb43bab237eedd0da214178801a9dd9822172d6
Parents: 81461dc
Author: Daniel Pravat <dp...@outlook.com>
Authored: Wed Sep 28 15:20:29 2016 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Wed Sep 28 17:29:23 2016 -0700
----------------------------------------------------------------------
3rdparty/stout/include/stout/os/windows/read.hpp | 6 ++++--
3rdparty/stout/include/stout/os/windows/sendfile.hpp | 10 ++++++++--
3rdparty/stout/include/stout/os/windows/write.hpp | 6 ++++--
3 files changed, 16 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/9bb43bab/3rdparty/stout/include/stout/os/windows/read.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/read.hpp b/3rdparty/stout/include/stout/os/windows/read.hpp
index cb0abf7..09190f9 100644
--- a/3rdparty/stout/include/stout/os/windows/read.hpp
+++ b/3rdparty/stout/include/stout/os/windows/read.hpp
@@ -29,11 +29,13 @@ inline Result<std::string> read(int fd, size_t size);
inline ssize_t read(int fd, void* data, size_t size)
{
+ CHECK_LE(size, UINT_MAX);
+
if (net::is_socket(fd)) {
- return ::recv(fd, (char*) data, size, 0);
+ return net::recv(fd, (char*) data, size, 0);
}
- return ::_read(fd, data, size);
+ return ::_read(fd, data, static_cast<unsigned int>(size));
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/9bb43bab/3rdparty/stout/include/stout/os/windows/sendfile.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/sendfile.hpp b/3rdparty/stout/include/stout/os/windows/sendfile.hpp
index 4c5178e..d6358cc 100644
--- a/3rdparty/stout/include/stout/os/windows/sendfile.hpp
+++ b/3rdparty/stout/include/stout/os/windows/sendfile.hpp
@@ -27,6 +27,10 @@ namespace os {
inline Try<ssize_t, SocketError> sendfile(
int s, int fd, off_t offset, size_t length)
{
+ // NOTE: We convert the `offset` here to avoid potential data loss
+ // in the type casting and bitshifting below.
+ uint64_t offset_ = offset;
+
// NOTE: It is not necessary to close the `HANDLE`; when we call `_close` on
// `fd` it will close the underlying `HANDLE` as well.
HANDLE file = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
@@ -34,10 +38,12 @@ inline Try<ssize_t, SocketError> sendfile(
OVERLAPPED from = {
0,
0,
- {static_cast<DWORD>(offset), static_cast<DWORD>(offset >> 32)},
+ {static_cast<DWORD>(offset_), static_cast<DWORD>(offset_ >> 32)},
nullptr};
- if (TransmitFile(s, file, length, 0, &from, nullptr, 0) == FALSE &&
+ CHECK_LE(length, MAXDWORD);
+ if (TransmitFile(
+ s, file, static_cast<DWORD>(length), 0, &from, nullptr, 0) == FALSE &&
(WSAGetLastError() == WSA_IO_PENDING ||
WSAGetLastError() == ERROR_IO_PENDING)) {
DWORD sent = 0;
http://git-wip-us.apache.org/repos/asf/mesos/blob/9bb43bab/3rdparty/stout/include/stout/os/windows/write.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/write.hpp b/3rdparty/stout/include/stout/os/windows/write.hpp
index 705ad03..2348870 100644
--- a/3rdparty/stout/include/stout/os/windows/write.hpp
+++ b/3rdparty/stout/include/stout/os/windows/write.hpp
@@ -30,11 +30,13 @@ inline Try<Nothing> write(int fd, const std::string& message);
inline ssize_t write(int fd, const void* data, size_t size)
{
+ CHECK_LE(size, INT_MAX);
+
if (net::is_socket(fd)) {
- return ::send(fd, (const char*) data, size, 0);
+ return net::send(fd, (const char*) data, size, 0);
}
- return ::_write(fd, data, size);
+ return ::_write(fd, data, static_cast<unsigned int>(size));
}