From 1cc730ddc27df52d757be1c2e7aa96193f8ca9df Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Thu, 1 Sep 2016 22:02:18 +0200 Subject: Use uint64_t for slash_bits consistently The VS compiler complained about possible loss of data (and it was right!) --- src/graph.cc | 4 ++-- src/graph.h | 9 +++++---- src/state.cc | 6 +++--- src/state.h | 7 ++++--- src/util_test.cc | 3 +-- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/graph.cc b/src/graph.cc index a5bac1c..e7f63fe 100644 --- a/src/graph.cc +++ b/src/graph.cc @@ -348,10 +348,10 @@ bool Edge::use_console() const { } // static -string Node::PathDecanonicalized(const string& path, unsigned int slash_bits) { +string Node::PathDecanonicalized(const string& path, uint64_t slash_bits) { string result = path; #ifdef _WIN32 - unsigned int mask = 1; + uint64_t mask = 1; for (char* c = &result[0]; (c = strchr(c, '/')) != NULL;) { if (slash_bits & mask) *c = '\\'; diff --git a/src/graph.h b/src/graph.h index add8d3d..ec24293 100644 --- a/src/graph.h +++ b/src/graph.h @@ -21,6 +21,7 @@ using namespace std; #include "eval_env.h" #include "timestamp.h" +#include "util.h" struct BuildLog; struct DiskInterface; @@ -33,7 +34,7 @@ struct State; /// Information about a node in the dependency graph: the file, whether /// it's dirty, mtime, etc. struct Node { - Node(const string& path, unsigned int slash_bits) + Node(const string& path, uint64_t slash_bits) : path_(path), slash_bits_(slash_bits), mtime_(-1), @@ -76,8 +77,8 @@ struct Node { return PathDecanonicalized(path_, slash_bits_); } static string PathDecanonicalized(const string& path, - unsigned int slash_bits); - unsigned int slash_bits() const { return slash_bits_; } + uint64_t slash_bits); + uint64_t slash_bits() const { return slash_bits_; } TimeStamp mtime() const { return mtime_; } @@ -101,7 +102,7 @@ private: /// Set bits starting from lowest for backslashes that were normalized to /// forward slashes by CanonicalizePath. See |PathDecanonicalized|. - unsigned int slash_bits_; + uint64_t slash_bits_; /// Possible values of mtime_: /// -1: file hasn't been examined diff --git a/src/state.cc b/src/state.cc index d539e7b..6079229 100644 --- a/src/state.cc +++ b/src/state.cc @@ -100,7 +100,7 @@ Edge* State::AddEdge(const Rule* rule) { return edge; } -Node* State::GetNode(StringPiece path, unsigned int slash_bits) { +Node* State::GetNode(StringPiece path, uint64_t slash_bits) { Node* node = LookupNode(path); if (node) return node; @@ -134,13 +134,13 @@ Node* State::SpellcheckNode(const string& path) { return result; } -void State::AddIn(Edge* edge, StringPiece path, unsigned int slash_bits) { +void State::AddIn(Edge* edge, StringPiece path, uint64_t slash_bits) { Node* node = GetNode(path, slash_bits); edge->inputs_.push_back(node); node->AddOutEdge(edge); } -bool State::AddOut(Edge* edge, StringPiece path, unsigned int slash_bits) { +bool State::AddOut(Edge* edge, StringPiece path, uint64_t slash_bits) { Node* node = GetNode(path, slash_bits); if (node->in_edge()) return false; diff --git a/src/state.h b/src/state.h index b530207..54e9dc5 100644 --- a/src/state.h +++ b/src/state.h @@ -23,6 +23,7 @@ using namespace std; #include "eval_env.h" #include "hash_map.h" +#include "util.h" struct Edge; struct Node; @@ -93,12 +94,12 @@ struct State { Edge* AddEdge(const Rule* rule); - Node* GetNode(StringPiece path, unsigned int slash_bits); + Node* GetNode(StringPiece path, uint64_t slash_bits); Node* LookupNode(StringPiece path) const; Node* SpellcheckNode(const string& path); - void AddIn(Edge* edge, StringPiece path, unsigned int slash_bits); - bool AddOut(Edge* edge, StringPiece path, unsigned int slash_bits); + void AddIn(Edge* edge, StringPiece path, uint64_t slash_bits); + bool AddOut(Edge* edge, StringPiece path, uint64_t slash_bits); bool AddDefault(StringPiece path, string* error); /// Reset state. Keeps all nodes and edges, but restores them to the diff --git a/src/util_test.cc b/src/util_test.cc index 64c2bbf..45d0727 100644 --- a/src/util_test.cc +++ b/src/util_test.cc @@ -290,8 +290,7 @@ TEST(CanonicalizePath, TooManyComponents) { "a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\a\\.\\x.h"; EXPECT_TRUE(CanonicalizePath(&path, &slash_bits, &err)); - printf("%x\n",slash_bits); - EXPECT_EQ(slash_bits, 0xffffffffLL); + EXPECT_EQ(slash_bits, 0xffffffff); // 65 is not. err = ""; -- cgit v0.12