r-lyeh-archived/fsm

crash

Opened this issue · 7 comments

It should crash if the queue std::deque< states::iterator > aborted has more than 2 elements .
Your Code is useful , Thank you very much !

hey,
can you paste a code snippet that crashes? i will take a look into it
thx

hey,
my crash code like this , may be it is logic unreasonable , but your attention is to delete all aborted
elements in function command , crash message : deque iterator not decrementable
cd_player cd;
cd.fsm.push(fsm::state(play));
cd.fsm.push(fsm::state(open));
cd.fsm.command(close);

forgive my poor english !

in order to avoid error , i try to change code like this :
// user commands
bool command(const fsm::state &trigger) {
size_t size = this->size();
if (!size) {
return false;
}
current_trigger = fsm::state();
std::deque< states::iterator > aborted;
for (auto it = deque.rbegin(); it != deque.rend(); ++it) {
fsm::state &self = _it;
if (!call(self, trigger)) {
aborted.push_back(it.base() - 1);
continue;
}
for (auto it = aborted.begin(), end = aborted.end(); it != end; ++it) {
call(__it, 'quit');
deque.erase(_it);
}
current_trigger = trigger;
return true;
}
return false;
}

@powerpeng

your code can`t build

@shafeng , i builded the code and it works , would you paste the error message please .

@powerpeng sorry , maybe my C++ compiler without C++11 support