From c4a9db2f981a03aecf5e9a60e6d27a6dc6dac159 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sat, 13 May 2017 00:29:50 +0300 Subject: Fix VC15 warnings (/W3) --- libbutl/fdstream.cxx | 26 ++++++++++++++++---------- libbutl/manifest-serializer.cxx | 4 ++-- libbutl/process.cxx | 2 +- libbutl/standard-version.cxx | 34 +++++++++++++++++++++------------- 4 files changed, 40 insertions(+), 26 deletions(-) (limited to 'libbutl') diff --git a/libbutl/fdstream.cxx b/libbutl/fdstream.cxx index a2d5b09..292324a 100644 --- a/libbutl/fdstream.cxx +++ b/libbutl/fdstream.cxx @@ -271,6 +271,14 @@ namespace butl return save () ? 0 : -1; } +#ifdef _WIN32 + static inline int + write (int fd, const void* buf, size_t n) + { + return _write (fd, buf, static_cast (n)); + } +#endif + bool fdbuf:: save () { @@ -282,11 +290,7 @@ namespace butl // descriptor opened for read-only access (while -1 with errno EBADF is // expected). This is in contrast with VC's _write() and POSIX's write(). // -#ifndef _WIN32 - ssize_t m (write (fd_.get (), buf_, n)); -#else - int m (_write (fd_.get (), buf_, n)); -#endif + auto m (write (fd_.get (), buf_, n)); if (m == -1) throw_ios_failure (errno); @@ -317,13 +321,15 @@ namespace butl // size_t n (static_cast (sn)); + auto advance = [this] (size_t n) {pbump (static_cast (n));}; + // Buffer the data if there is enough space. // size_t an (epptr () - pptr ()); // Amount of free space in the buffer. if (n <= an) { memcpy (pptr (), s, n); - pbump (n); + advance (n); return n; } @@ -377,13 +383,13 @@ namespace butl else { memcpy (pptr (), s, an); - pbump (an); + advance (an); } // Flush the buffer. // size_t wn (bn + an); - int r (wn > 0 ? _write (fd_.get (), buf_, wn) : 0); + int r (wn > 0 ? write (fd_.get (), buf_, wn) : 0); if (r == -1) throw_ios_failure (errno); @@ -413,13 +419,13 @@ namespace butl if (n <= static_cast (epptr () - pbase ())) { memcpy (pbase (), s, n); - pbump (n); + advance (n); return sn; } // The data tail doesn't fit the buffer so write it to the file. // - r = _write (fd_.get (), s, n); + r = write (fd_.get (), s, n); if (r == -1) throw_ios_failure (errno); diff --git a/libbutl/manifest-serializer.cxx b/libbutl/manifest-serializer.cxx index 96661df..35f2d72 100644 --- a/libbutl/manifest-serializer.cxx +++ b/libbutl/manifest-serializer.cxx @@ -185,7 +185,7 @@ namespace butl // Is this whitespace past where we need to break? Also see // below the "hard" break case for why we use 78 at the end. // - if (cl + static_cast (w - s) > (w != e ? 77 : 78)) + if (cl + static_cast (w - s) > (w != e ? 77U : 78U)) { // Only break if this whitespace is close enough to // the end of the line. @@ -203,7 +203,7 @@ namespace butl // '\' and then the character on the next line, we might as well // write it on this line. // - if (cl >= (s + 1 != e ? 77 : 78)) + if (cl >= (s + 1 != e ? 77U : 78U)) br = true; if (br) diff --git a/libbutl/process.cxx b/libbutl/process.cxx index 478793e..af5cc73 100644 --- a/libbutl/process.cxx +++ b/libbutl/process.cxx @@ -1192,7 +1192,7 @@ namespace butl // Detect if this is an MSYS2 process by checking if the process has // loaded msys-2.0.dll. // - size_t wait (300); + DWORD wait (300); if (!msys) { diff --git a/libbutl/standard-version.cxx b/libbutl/standard-version.cxx index 124f3de..13d3987 100644 --- a/libbutl/standard-version.cxx +++ b/libbutl/standard-version.cxx @@ -19,9 +19,9 @@ namespace butl // Utility functions // static uint64_t - parse_num (const string& s, size_t& p, - const char* m, - uint64_t min = 0, uint64_t max = 999) + parse_uint64 (const string& s, size_t& p, + const char* m, + uint64_t min, uint64_t max) { if (s[p] == '-' || s[p] == '+') // strtoull() allows these. throw invalid_argument (m); @@ -37,6 +37,14 @@ namespace butl return static_cast (r); } + static uint16_t + parse_uint16 (const string& s, size_t& p, + const char* m, + uint16_t min = 0, uint16_t max = 999) + { + return static_cast (parse_uint64 (s, p, m, min, max)); + } + static void check_version (uint64_t vr, bool sn, standard_version::flags fl) { @@ -120,14 +128,14 @@ namespace butl if (ep) { - epoch = parse_num (s, p, "invalid epoch", 1, uint16_t (~0)); + epoch = parse_uint16 (s, p, "invalid epoch", 1, uint16_t (~0)); ++p; // Skip '~'. } uint16_t ma, mi, bf, ab (0); bool earliest (false); - ma = parse_num (s, p, "invalid major version"); + ma = parse_uint16 (s, p, "invalid major version"); // The only valid version that has no epoch, contains only the major // version being equal to zero, that is optionally followed by the plus @@ -143,12 +151,12 @@ namespace butl if (s[p] != '.') bail ("'.' expected after major version"); - mi = parse_num (s, ++p, "invalid minor version"); + mi = parse_uint16 (s, ++p, "invalid minor version"); if (s[p] != '.') bail ("'.' expected after minor version"); - bf = parse_num (s, ++p, "invalid patch version"); + bf = parse_uint16 (s, ++p, "invalid patch version"); // AAABBBCCCDDDE version = ma * 10000000000ULL + @@ -177,7 +185,7 @@ namespace butl if (s[++p] != '.') bail ("'.' expected after pre-release letter"); - ab = parse_num (s, ++p, "invalid pre-release", 0, 499); + ab = parse_uint16 (s, ++p, "invalid pre-release", 0, 499); if (k == 'b') ab += 500; @@ -197,7 +205,7 @@ namespace butl { assert (!earliest); // Would bail out earlier (a or b expected after -). - revision = parse_num (s, ++p, "invalid revision", 1, uint16_t (~0)); + revision = parse_uint16 (s, ++p, "invalid revision", 1, uint16_t (~0)); } if (p != n) @@ -293,10 +301,10 @@ namespace butl return; } - uint64_t sn (parse_num (s, - p, - "invalid snapshot number", - 1, latest_sn - 1)); + uint64_t sn (parse_uint64 (s, + p, + "invalid snapshot number", + 1, latest_sn - 1)); std::string id; if (s[p] == '.') { -- cgit v1.1