diff options
author | Nico Weber <thakis@chromium.org> | 2013-08-28 22:00:05 (GMT) |
---|---|---|
committer | Nico Weber <thakis@chromium.org> | 2013-08-28 22:00:05 (GMT) |
commit | 65120c69372cd35809168115a9fc2a12868eb4aa (patch) | |
tree | 2f19421bf5374ad6acf21e393a3915c2935ca3cf /src | |
parent | f92a6dfe168e4e4f2ed8592f9be1d176dc4e1179 (diff) | |
download | Ninja-65120c69372cd35809168115a9fc2a12868eb4aa.zip Ninja-65120c69372cd35809168115a9fc2a12868eb4aa.tar.gz Ninja-65120c69372cd35809168115a9fc2a12868eb4aa.tar.bz2 |
Fix an issue with more than 64k deps, spotted by maximuska.
Also add a test for this case, which would have spotted the issue too.
Diffstat (limited to 'src')
-rw-r--r-- | src/deps_log.cc | 2 | ||||
-rw-r--r-- | src/deps_log_test.cc | 33 |
2 files changed, 34 insertions, 1 deletions
diff --git a/src/deps_log.cc b/src/deps_log.cc index 64ef58f..ceee68a 100644 --- a/src/deps_log.cc +++ b/src/deps_log.cc @@ -124,7 +124,7 @@ bool DepsLog::RecordDeps(Node* node, TimeStamp mtime, return true; // Update on-disk representation. - unsigned size = 4 * (1 + 1 + (uint16_t)node_count); + unsigned size = 4 * (1 + 1 + node_count); if (size > kMaxRecordSize) { errno = ERANGE; return false; diff --git a/src/deps_log_test.cc b/src/deps_log_test.cc index 3b32963..4e6cbac 100644 --- a/src/deps_log_test.cc +++ b/src/deps_log_test.cc @@ -82,6 +82,39 @@ TEST_F(DepsLogTest, WriteRead) { ASSERT_EQ("bar2.h", log_deps->nodes[1]->path()); } +TEST_F(DepsLogTest, LotsOfDeps) { + const int kNumDeps = 100000; // More than 64k. + + State state1; + DepsLog log1; + string err; + EXPECT_TRUE(log1.OpenForWrite(kTestFilename, &err)); + ASSERT_EQ("", err); + + { + vector<Node*> deps; + for (int i = 0; i < kNumDeps; ++i) { + char buf[32]; + sprintf(buf, "file%d.h", i); + deps.push_back(state1.GetNode(buf)); + } + log1.RecordDeps(state1.GetNode("out.o"), 1, deps); + + DepsLog::Deps* log_deps = log1.GetDeps(state1.GetNode("out.o")); + ASSERT_EQ(kNumDeps, log_deps->node_count); + } + + log1.Close(); + + State state2; + DepsLog log2; + EXPECT_TRUE(log2.Load(kTestFilename, &state2, &err)); + ASSERT_EQ("", err); + + DepsLog::Deps* log_deps = log2.GetDeps(state2.GetNode("out.o")); + ASSERT_EQ(kNumDeps, log_deps->node_count); +} + // Verify that adding the same deps twice doesn't grow the file. TEST_F(DepsLogTest, DoubleEntry) { // Write some deps to the file and grab its size. |