Permalink
Browse files

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.)
  • Loading branch information...
1 parent d58a109 commit 09775f02209a07a4e1032b9ab9d8ce5f0ff8d583 @evmar evmar committed Aug 10, 2012
Showing with 14 additions and 6 deletions.
  1. +3 −0 configure.py
  2. +1 −1 src/canon_perftest.cc
  3. +7 −2 src/hash_collision_bench.cc
  4. +3 −3 src/util_test.cc
View
@@ -110,6 +110,9 @@ def binary(name):
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']
View
@@ -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) {
@@ -14,6 +14,11 @@
#include "build_log.h"
+#include <algorithm>
+using namespace std;
+
+#include <time.h>
+
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<uint64_t, int>* hashes = new pair<uint64_t, int>[N];
- srand(time(NULL));
+ srand((int)time(NULL));
for (int i = 0; i < N; ++i) {
RandomCommand(&commands[i]);
View
@@ -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<size_t>(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<size_t>(len));
+ EXPECT_EQ(strlen("file"), len);
EXPECT_EQ("file ./file bar/.", string(path));
}

0 comments on commit 09775f0

Please sign in to comment.