From ee39338225ed30e47bf066f29d239f0aa09efa8c Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 19 May 2016 02:25:09 +0300 Subject: libservice: fix compiler warnings --- utils/libservice/CMakeLists.txt | 1 + utils/libservice/src/device.cpp | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'utils/libservice') 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 +#include +#include #include #include #include @@ -54,11 +56,14 @@ namespace libservice { DWORD nbreq; + if (in_buf_size > std::numeric_limits::max()) + throw std::range_error("input buffer size is too large"); + std::size_t nbwritten = DeviceIoControl( handle, code, const_cast(in_buf), - in_buf_size, + static_cast(in_buf_size), NULL, 0, &nbreq, @@ -91,13 +96,18 @@ namespace libservice { DWORD nbreq; + if (in_buf_size > std::numeric_limits::max()) + throw std::range_error("input buffer size is too large"); + if (out_buf_size > std::numeric_limits::max()) + throw std::range_error("output buffer size is too large"); + std::size_t nbwritten = DeviceIoControl( handle, code, const_cast(in_buf), - in_buf_size, + static_cast(in_buf_size), out_buf, - out_buf_size, + static_cast(out_buf_size), &nbreq, NULL); -- cgit v1.2.3