Skip to content

Commit

Permalink
Merge pull request #1291 from colincross/fix1290
Browse files Browse the repository at this point in the history
Fix segfault on edge with no inputs
  • Loading branch information
nico committed Jun 18, 2017
2 parents 00f69c1 + 11a934d commit 1029064
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/build_test.cc
Expand Up @@ -1305,6 +1305,37 @@ TEST_F(BuildWithLogTest, RebuildAfterFailure) {
EXPECT_EQ("", err);
}

TEST_F(BuildWithLogTest, RebuildWithNoInputs) {
ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
"rule touch\n"
" command = touch\n"
"build out1: touch\n"
"build out2: touch in\n"));

string err;

fs_.Create("in", "");

EXPECT_TRUE(builder_.AddTarget("out1", &err));
EXPECT_TRUE(builder_.AddTarget("out2", &err));
EXPECT_TRUE(builder_.Build(&err));
EXPECT_EQ("", err);
EXPECT_EQ(2u, command_runner_.commands_ran_.size());

command_runner_.commands_ran_.clear();
state_.Reset();

fs_.Tick();

fs_.Create("in", "");

EXPECT_TRUE(builder_.AddTarget("out1", &err));
EXPECT_TRUE(builder_.AddTarget("out2", &err));
EXPECT_TRUE(builder_.Build(&err));
EXPECT_EQ("", err);
EXPECT_EQ(1u, command_runner_.commands_ran_.size());
}

TEST_F(BuildWithLogTest, RestatTest) {
ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
"rule true\n"
Expand Down
2 changes: 1 addition & 1 deletion src/graph.cc
Expand Up @@ -193,7 +193,7 @@ bool DependencyScan::RecomputeOutputDirty(Edge* edge,
EXPLAIN("command line changed for %s", output->path().c_str());
return true;
}
if (entry->mtime < most_recent_input->mtime()) {
if (most_recent_input && entry->mtime < most_recent_input->mtime()) {
// May also be dirty due to the mtime in the log being older than the
// mtime of the most recent input. This can occur even when the mtime
// on disk is newer if a previous run wrote to the output file but
Expand Down

0 comments on commit 1029064

Please sign in to comment.