From fe2c12bfe9fdc2713724bb400172e9915477cd65 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 4 May 2021 15:39:47 +0300 Subject: fix compiler warnings --- src/handle.cpp | 10 ++++++++-- src/path.cpp | 7 ++++++- src/process.cpp | 6 +++++- 3 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src') 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 #include +#include #include #include #include @@ -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::max()) + throw std::range_error{"Read buffer is too large"}; + const auto ret = + ::ReadFile(m_impl.get(), buffer.data(), static_cast(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::max()) + throw std::range_error{"Write buffer is too large"}; + const auto ret = ::WriteFile(m_impl.get(), data, static_cast(nb), &nb_written, NULL); if (!ret) { throw error::windows(GetLastError(), "WriteFile"); diff --git a/src/path.cpp b/src/path.cpp index 3df5918..7848df2 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -9,6 +9,8 @@ #include +#include +#include #include #include @@ -23,7 +25,10 @@ std::wstring do_canonicalize(const std::wstring& path) { buffer.resize(init_buffer_size); while (true) { - const auto nch = ::GetFullPathNameW(path.c_str(), buffer.size(), buffer.data(), NULL); + if (buffer.size() > std::numeric_limits::max()) + throw std::range_error{"Path buffer is too large"}; + const auto nch = ::GetFullPathNameW( + path.c_str(), static_cast(buffer.size()), buffer.data(), NULL); if (nch == 0) { throw error::windows(GetLastError(), "GetFullPathNameW"); diff --git a/src/process.cpp b/src/process.cpp index bac8bb8..2be7f0d 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -305,7 +306,10 @@ std::string Process::get_exe_path() { while (true) { SetLastError(ERROR_SUCCESS); - const auto nch = ::GetModuleFileNameW(NULL, buffer.data(), buffer.size()); + if (buffer.size() > std::numeric_limits::max()) + throw std::range_error{"Path buffer is too large"}; + const auto nch = + ::GetModuleFileNameW(NULL, buffer.data(), static_cast(buffer.size())); if (nch == 0) { throw error::windows(GetLastError(), "GetModuleFileNameW"); -- cgit v1.2.3