aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-05-19 02:25:09 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-05-19 02:25:09 +0300
commitee39338225ed30e47bf066f29d239f0aa09efa8c (patch)
treeb212d9b51f17a55ad812fea7d3727586c90a2003
parentrename the project (diff)
downloadwindows7-drivers-ee39338225ed30e47bf066f29d239f0aa09efa8c.tar.gz
windows7-drivers-ee39338225ed30e47bf066f29d239f0aa09efa8c.zip
libservice: fix compiler warnings
-rw-r--r--utils/libservice/CMakeLists.txt1
-rw-r--r--utils/libservice/src/device.cpp16
2 files changed, 14 insertions, 3 deletions
diff --git a/utils/libservice/CMakeLists.txt b/utils/libservice/CMakeLists.txt
index 720a44b..34b3d13 100644
--- a/utils/libservice/CMakeLists.txt
+++ b/utils/libservice/CMakeLists.txt
@@ -4,6 +4,7 @@ add_library(libservice
${libservice_sources}
${libservice_headers})
target_include_directories(libservice PUBLIC include)
+target_compile_definitions(libservice PRIVATE NOMINMAX)
add_subdirectory(test)
add_subdirectory(utils)
diff --git a/utils/libservice/src/device.cpp b/utils/libservice/src/device.cpp
index 4ae25a5..825c2bc 100644
--- a/utils/libservice/src/device.cpp
+++ b/utils/libservice/src/device.cpp
@@ -12,6 +12,8 @@
#include <cstddef>
+#include <limits>
+#include <stdexcept>
#include <string>
#include <system_error>
#include <utility>
@@ -54,11 +56,14 @@ namespace libservice
{
DWORD nbreq;
+ if (in_buf_size > std::numeric_limits<DWORD>::max())
+ throw std::range_error("input buffer size is too large");
+
std::size_t nbwritten = DeviceIoControl(
handle,
code,
const_cast<void*>(in_buf),
- in_buf_size,
+ static_cast<DWORD>(in_buf_size),
NULL,
0,
&nbreq,
@@ -91,13 +96,18 @@ namespace libservice
{
DWORD nbreq;
+ if (in_buf_size > std::numeric_limits<DWORD>::max())
+ throw std::range_error("input buffer size is too large");
+ if (out_buf_size > std::numeric_limits<DWORD>::max())
+ throw std::range_error("output buffer size is too large");
+
std::size_t nbwritten = DeviceIoControl(
handle,
code,
const_cast<void*>(in_buf),
- in_buf_size,
+ static_cast<DWORD>(in_buf_size),
out_buf,
- out_buf_size,
+ static_cast<DWORD>(out_buf_size),
&nbreq,
NULL);