diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2021-05-04 15:39:47 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2021-05-04 16:01:48 +0300 |
commit | fe2c12bfe9fdc2713724bb400172e9915477cd65 (patch) | |
tree | e4445ee6344602d3676e59473cb410905a7a72ce /src/handle.cpp | |
parent | get rid of SafeInt (diff) | |
download | winapi-common-fe2c12bfe9fdc2713724bb400172e9915477cd65.tar.gz winapi-common-fe2c12bfe9fdc2713724bb400172e9915477cd65.zip |
fix compiler warnings
Diffstat (limited to 'src/handle.cpp')
-rw-r--r-- | src/handle.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/handle.cpp b/src/handle.cpp index 4678519..ba1e4b5 100644 --- a/src/handle.cpp +++ b/src/handle.cpp @@ -14,6 +14,7 @@ #include <cassert> #include <cstddef> +#include <limits> #include <sstream> #include <stdexcept> #include <utility> @@ -83,7 +84,10 @@ bool Handle::read_chunk(Buffer& buffer) const { buffer.resize(max_chunk_size); DWORD nb_read = 0; - const auto ret = ::ReadFile(m_impl.get(), buffer.data(), buffer.size(), &nb_read, NULL); + if (buffer.size() > std::numeric_limits<DWORD>::max()) + throw std::range_error{"Read buffer is too large"}; + const auto ret = + ::ReadFile(m_impl.get(), buffer.data(), static_cast<DWORD>(buffer.size()), &nb_read, NULL); buffer.resize(nb_read); @@ -121,7 +125,9 @@ Buffer Handle::read() const { void Handle::write(const void* data, std::size_t nb) const { DWORD nb_written = 0; - const auto ret = ::WriteFile(m_impl.get(), data, nb, &nb_written, NULL); + if (nb > std::numeric_limits<DWORD>::max()) + throw std::range_error{"Write buffer is too large"}; + const auto ret = ::WriteFile(m_impl.get(), data, static_cast<DWORD>(nb), &nb_written, NULL); if (!ret) { throw error::windows(GetLastError(), "WriteFile"); |