boost-ext / sml

C++14 State Machine library
https://boost-ext.github.io/sml
Boost Software License 1.0
1.15k stars 178 forks source link

segfault on dependency passed as pointer and used as const pointer #233

Closed etam closed 5 years ago

etam commented 5 years ago

MWE:

#include <iostream>
#include <boost/sml.hpp>

struct e1 {};

const auto guard = [](const int* i)
{
    // segfaults on dereferencing i
    std::cout << "guard " << *i << '\n';
    return true;
};

const auto action = [](int* i)
{
    std::cout << "action " << *i << '\n';
};

struct TransitionTable
{
    auto operator()() const
    {
        using namespace boost::sml;
        return make_transition_table(
            *"s"_s + event<e1> [ guard ] / action
        );
    }
};

int main()
{
    int i = 5;
    boost::sml::sm<TransitionTable> sm{&i};
    sm.process_event(e1{});
}

guard takes dependency as const int* and is given nullptr. If it's changed to int* it works as expected.

krzysztof-jusiak commented 5 years ago

In the current SML version, const/non-const types have to be passed separately. That will most likely change in the future though.

https://wandbox.org/permlink/OClASgiAw8Kl5du6