Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 931b19d

Browse files
committed
Merge pull request ninja-build#555 from nico/depscompactcrash
Don't crash during deps log recompaction if there's more than one deps entry.
2 parents 3699cb6 + 2b26bf2 commit 931b19d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/deps_log.cc

+2
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ bool DepsLog::Recompact(const string& path, string* err) {
257257
// Write out all deps again.
258258
for (int old_id = 0; old_id < (int)deps_.size(); ++old_id) {
259259
Deps* deps = deps_[old_id];
260+
if (!deps) continue; // If nodes_[old_id] is a leaf, it has no deps.
261+
260262
if (!new_log.RecordDeps(nodes_[old_id], deps->mtime,
261263
deps->node_count, deps->nodes)) {
262264
new_log.Close();

src/deps_log_test.cc

+6
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ TEST_F(DepsLogTest, Recompact) {
137137
deps.push_back(state.GetNode("foo.h"));
138138
deps.push_back(state.GetNode("bar.h"));
139139
log.RecordDeps(state.GetNode("out.o"), 1, deps);
140+
141+
deps.clear();
142+
deps.push_back(state.GetNode("foo.h"));
143+
deps.push_back(state.GetNode("baz.h"));
144+
log.RecordDeps(state.GetNode("other_out.o"), 1, deps);
145+
140146
log.Close();
141147

142148
struct stat st;

0 commit comments

Comments
 (0)