From 293acf06408f9a19a563633f87a6fe93327fd0b4 Mon Sep 17 00:00:00 2001 From: Zachary Henkel Date: Wed, 9 Dec 2015 13:59:32 -0800 Subject: [PATCH] Add casts to eliminate signed/unsigned mismatch warnings Addresses issue #210 and VC's warning C4365 --- include/string_span.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/string_span.h b/include/string_span.h index a451314..feb5ac6 100644 --- a/include/string_span.h +++ b/include/string_span.h @@ -111,28 +111,28 @@ inline span ensure_z(T* const & sz, std::ptrdiff_t max = PTRDI // TODO (neilmac) there is probably a better template-magic way to get the const and non-const overloads to share an implementation inline span ensure_z(char* const& sz, std::ptrdiff_t max) { - auto len = strnlen(sz, max); + auto len = strnlen(sz, narrow_cast(max)); Ensures(sz[len] == 0); return{ sz, static_cast(len) }; } inline span ensure_z(const char* const& sz, std::ptrdiff_t max) { - auto len = strnlen(sz, max); + auto len = strnlen(sz, narrow_cast(max)); Ensures(sz[len] == 0); return{ sz, static_cast(len) }; } inline span ensure_z(wchar_t* const& sz, std::ptrdiff_t max) { - auto len = wcsnlen(sz, max); + auto len = wcsnlen(sz, narrow_cast(max)); Ensures(sz[len] == 0); return{ sz, static_cast(len) }; } inline span ensure_z(const wchar_t* const& sz, std::ptrdiff_t max) { - auto len = wcsnlen(sz, max); + auto len = wcsnlen(sz, narrow_cast(max)); Ensures(sz[len] == 0); return{ sz, static_cast(len) }; } @@ -172,7 +172,7 @@ namespace details { std::ptrdiff_t operator()(char* const ptr, std::ptrdiff_t length) noexcept { - return narrow_cast(strnlen(ptr, length)); + return narrow_cast(strnlen(ptr, narrow_cast(length))); } }; @@ -181,7 +181,7 @@ namespace details { std::ptrdiff_t operator()(wchar_t* const ptr, std::ptrdiff_t length) noexcept { - return narrow_cast(wcsnlen(ptr, length)); + return narrow_cast(wcsnlen(ptr, narrow_cast(length))); } }; @@ -190,7 +190,7 @@ namespace details { std::ptrdiff_t operator()(const char* const ptr, std::ptrdiff_t length) noexcept { - return narrow_cast(strnlen(ptr, length)); + return narrow_cast(strnlen(ptr, narrow_cast(length))); } }; @@ -199,7 +199,7 @@ namespace details { std::ptrdiff_t operator()(const wchar_t* const ptr, std::ptrdiff_t length) noexcept { - return narrow_cast(wcsnlen(ptr, length)); + return narrow_cast(wcsnlen(ptr, narrow_cast(length))); } }; }