aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-05-13 00:29:50 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-05-15 15:58:03 +0300
commitc4a9db2f981a03aecf5e9a60e6d27a6dc6dac159 (patch)
treeb40c731b0e1ebdc8abdafddfadc919b64baef8f0
parent041b2137f7351abc8d648ed6a0399feaf331af08 (diff)
Fix VC15 warnings (/W3)
-rw-r--r--libbutl/fdstream.cxx26
-rw-r--r--libbutl/manifest-serializer.cxx4
-rw-r--r--libbutl/process.cxx2
-rw-r--r--libbutl/standard-version.cxx34
-rw-r--r--tests/manifest-parser/driver.cxx2
-rw-r--r--tests/manifest-serializer/driver.cxx2
-rw-r--r--tests/process/driver.cxx7
-rw-r--r--tests/target-triplet/driver.cxx2
-rw-r--r--tests/timestamp/driver.cxx10
9 files changed, 57 insertions, 32 deletions
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<unsigned int> (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<size_t> (sn));
+ auto advance = [this] (size_t n) {pbump (static_cast<int> (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<size_t> (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<size_t> (w - s) > (w != e ? 77 : 78))
+ if (cl + static_cast<size_t> (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<uint64_t> (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<uint16_t> (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] == '.')
{
diff --git a/tests/manifest-parser/driver.cxx b/tests/manifest-parser/driver.cxx
index 7642f4b..e480508 100644
--- a/tests/manifest-parser/driver.cxx
+++ b/tests/manifest-parser/driver.cxx
@@ -198,7 +198,7 @@ fail (const char* m)
cerr << "nofail: " << r << endl;
return false;
}
- catch (const manifest_parsing& e)
+ catch (const manifest_parsing&)
{
//cerr << e << endl;
}
diff --git a/tests/manifest-serializer/driver.cxx b/tests/manifest-serializer/driver.cxx
index d148f12..3a8aef8 100644
--- a/tests/manifest-serializer/driver.cxx
+++ b/tests/manifest-serializer/driver.cxx
@@ -247,7 +247,7 @@ fail (const pairs& m)
cerr << "nofail: " << r << endl;
return false;
}
- catch (const manifest_serialization& e)
+ catch (const manifest_serialization&)
{
//cerr << e << endl;
}
diff --git a/tests/process/driver.cxx b/tests/process/driver.cxx
index bdc5f4a..b154bce 100644
--- a/tests/process/driver.cxx
+++ b/tests/process/driver.cxx
@@ -294,8 +294,13 @@ main (int argc, const char* argv[])
v.reserve (5000 * 256);
for (size_t i (0); i < 5000; ++i)
{
- for (size_t c (0); c < 256; ++c)
+ char c (numeric_limits<char>::min ());
+
+ do
+ {
v.push_back (c);
+ }
+ while (c++ != numeric_limits<char>::max ());
}
assert (exec (p, v, true, true));
diff --git a/tests/target-triplet/driver.cxx b/tests/target-triplet/driver.cxx
index 8691bac..b446a6f 100644
--- a/tests/target-triplet/driver.cxx
+++ b/tests/target-triplet/driver.cxx
@@ -152,7 +152,7 @@ fail (const char* s)
cerr << "nofail: " << s << endl;
return false;
}
- catch (invalid_argument& e)
+ catch (const invalid_argument&)
{
//cerr << e << endl;
}
diff --git a/tests/timestamp/driver.cxx b/tests/timestamp/driver.cxx
index b268e00..d1e8d2c 100644
--- a/tests/timestamp/driver.cxx
+++ b/tests/timestamp/driver.cxx
@@ -2,7 +2,7 @@
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
-#include <time.h> // tzset()
+#include <time.h> // tzset() (POSIX), _tzset() (Windows)
#include <chrono>
#include <locale>
@@ -80,7 +80,13 @@ ns (unsigned long long t)
int
main ()
{
- tzset (); // To use butl::to_stream() later on.
+ // To use butl::to_stream() later on.
+ //
+#ifndef _WIN32
+ tzset ();
+#else
+ _tzset ();
+#endif
// Invalid %[].
//