Skip to content

Commit

Permalink
chapter_02: section_2_4_4_minimal_dfa_with_hopcrofts_algorithm: Fix c…
Browse files Browse the repository at this point in the history
…rash

This fixes the crash mentioned in Issue #2:
#2
by chakpongchung, caused by an attempt to dereference an empty
iterator.
  • Loading branch information
murraycu committed Mar 15, 2019
1 parent f7a305f commit ceb393d
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ split(const States& states, const Partitions& partitions) {
// DFAs, by definition, have at most 1 transition per character per state:
assert(next_states.size() <= 1);

const auto next = *(next_states.begin());
const auto next = next_states.empty() ?
std::shared_ptr<State>{} : // A state with no transition.
*(next_states.begin());
const auto next_partition =
get_partition_containing_state(partitions, next);
states_by_next_partition[next_partition].emplace(s);
Expand Down

0 comments on commit ceb393d

Please sign in to comment.