diff --git a/spot/twa/acc.hh b/spot/twa/acc.hh index 6ddde3ef8..6192e9dba 100644 --- a/spot/twa/acc.hh +++ b/spot/twa/acc.hh @@ -102,7 +102,10 @@ namespace spot : mark_t(_value_t::zero()) { for (iterator i = begin; i != end; ++i) - set(*i); + if (SPOT_LIKELY(*i < SPOT_MAX_ACCSETS)) + set(*i); + else + report_too_many_sets(); } /// Create a mark_t from a list of set numbers. diff --git a/tests/core/acc.cc b/tests/core/acc.cc index 91e829724..74c32fa49 100644 --- a/tests/core/acc.cc +++ b/tests/core/acc.cc @@ -53,6 +53,17 @@ static void print(const std::vector>& res) } } +static void expect(const std::exception& e, const char* prefix) +{ + if (std::strncmp(e.what(), "Too many acceptance sets used.", + strlen(prefix))) + { + std::cerr << "exception: " << e.what() << '\n'; + std::cerr << "expected: " << prefix << '\n'; + abort(); + } +} + int main() { spot::acc_cond ac(4); @@ -189,7 +200,7 @@ int main() } catch (const std::runtime_error& e) { - assert(!std::strncmp(e.what(), "Too many acceptance sets used.", 30)); + expect(e, "Too many acceptance sets used."); } #if SPOT_DEBUG @@ -204,7 +215,7 @@ int main() } catch (const std::runtime_error& e) { - assert(!std::strncmp(e.what(), "Too many acceptance sets used.", 30)); + expect(e, "Too many acceptance sets used."); } try @@ -214,17 +225,17 @@ int main() } catch (const std::runtime_error& e) { - assert(!std::strncmp(e.what(), "Too many acceptance sets used.", 30)); + expect(e, "Too many acceptance sets used."); } +#endif try { spot::acc_cond::mark_t m{spot::acc_cond::mark_t::max_accsets()}; } catch (const std::runtime_error& e) { - assert(!std::strcmp(e.what(), "bit index is out of bounds")); + expect(e, "Too many acceptance sets used."); } -#endif return 0; } diff --git a/tests/python/except.py b/tests/python/except.py index 598d70b6a..f4ece980b 100644 --- a/tests/python/except.py +++ b/tests/python/except.py @@ -169,7 +169,7 @@ else: try: m = spot.mark_t([0, n, 1]) except RuntimeError as e: - assert "bit index is out of bounds" in str(e) + assert "Too many acceptance sets used. The limit is" in str(e) else: report_missing_exception()