From 09775f02209a07a4e1032b9ab9d8ce5f0ff8d583 Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Fri, 10 Aug 2012 13:39:25 -0700 Subject: windows: fix integer truncation issues for helper binaries Disable the size_t truncation warning. (Note that this leaves on the other truncation-related warnings, like int->char.) --- configure.py | 3 +++ src/canon_perftest.cc | 2 +- src/hash_collision_bench.cc | 9 +++++++-- src/util_test.cc | 6 +++--- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/configure.py b/configure.py index 95f88b1..76abc72 100755 --- a/configure.py +++ b/configure.py @@ -110,6 +110,9 @@ else: if platform == 'windows': cflags = ['/nologo', '/Zi', '/W4', '/WX', '/wd4530', '/wd4100', '/wd4706', '/wd4512', '/wd4800', '/wd4702', '/wd4819', '/GR-', + # Disable size_t -> int truncation warning. + # We never have strings or arrays larger than 2**31. + '/wd4267', '/DNOMINMAX', '/D_CRT_SECURE_NO_WARNINGS', '/DNINJA_PYTHON="%s"' % options.with_python] ldflags = ['/DEBUG', '/libpath:$builddir'] diff --git a/src/canon_perftest.cc b/src/canon_perftest.cc index d0ed397..59bd18f 100644 --- a/src/canon_perftest.cc +++ b/src/canon_perftest.cc @@ -27,7 +27,7 @@ int main() { string err; char buf[200]; - int len = strlen(kPath); + size_t len = strlen(kPath); strcpy(buf, kPath); for (int j = 0; j < 5; ++j) { diff --git a/src/hash_collision_bench.cc b/src/hash_collision_bench.cc index 6736109..d0eabde 100644 --- a/src/hash_collision_bench.cc +++ b/src/hash_collision_bench.cc @@ -14,6 +14,11 @@ #include "build_log.h" +#include +using namespace std; + +#include + int random(int low, int high) { return int(low + (rand() / double(RAND_MAX)) * (high - low) + 0.5); } @@ -22,7 +27,7 @@ void RandomCommand(char** s) { int len = random(5, 100); *s = new char[len]; for (int i = 0; i < len; ++i) - (*s)[i] = random(32, 127); + (*s)[i] = (char)random(32, 127); } int main() { @@ -32,7 +37,7 @@ int main() { char** commands = new char*[N]; pair* hashes = new pair[N]; - srand(time(NULL)); + srand((int)time(NULL)); for (int i = 0; i < N; ++i) { RandomCommand(&commands[i]); diff --git a/src/util_test.cc b/src/util_test.cc index 5ace5e7..7a34671 100644 --- a/src/util_test.cc +++ b/src/util_test.cc @@ -105,18 +105,18 @@ TEST(CanonicalizePath, AbsolutePath) { TEST(CanonicalizePath, NotNullTerminated) { string path; string err; - int len; + size_t len; path = "foo/. bar/."; len = strlen("foo/."); // Canonicalize only the part before the space. EXPECT_TRUE(CanonicalizePath(&path[0], &len, &err)); - EXPECT_EQ(strlen("foo"), static_cast(len)); + EXPECT_EQ(strlen("foo"), len); EXPECT_EQ("foo/. bar/.", string(path)); path = "foo/../file bar/."; len = strlen("foo/../file"); EXPECT_TRUE(CanonicalizePath(&path[0], &len, &err)); - EXPECT_EQ(strlen("file"), static_cast(len)); + EXPECT_EQ(strlen("file"), len); EXPECT_EQ("file ./file bar/.", string(path)); } -- cgit v0.12