From e37fa6524786b787e2e5eb98605dc51cae7b527f Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 4 Jul 2021 11:00:38 +0200 Subject: [PATCH] arcm:: fixed the possible crash on deleting arcms with large cells, because of the confusion of cdata --- arbitrile.cpp | 6 ------ archimedean.cpp | 4 ---- cell.cpp | 4 ++-- locations.cpp | 6 ++++-- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/arbitrile.cpp b/arbitrile.cpp index 32e307b2..8d434d09 100644 --- a/arbitrile.cpp +++ b/arbitrile.cpp @@ -694,12 +694,6 @@ struct hrmap_arbi : hrmap { } ~hrmap_arbi() { - /* - if(hyperbolic) for(auto& p: arbi_matrix) if(p.second.first->cdata) { - delete p.second.first->cdata; - p.second.first->cdata = NULL; - } - */ clearfrom(origin); altmap.clear(); arbi_matrix.clear(); diff --git a/archimedean.cpp b/archimedean.cpp index 6287d8a7..19d50778 100644 --- a/archimedean.cpp +++ b/archimedean.cpp @@ -585,10 +585,6 @@ struct hrmap_archimedean : hrmap { } ~hrmap_archimedean() { - if(hyperbolic) for(auto& p: archimedean_gmatrix) if(p.second.first->cdata) { - delete p.second.first->cdata; - p.second.first->cdata = NULL; - } clearfrom(origin); altmap.clear(); archimedean_gmatrix.clear(); diff --git a/cell.cpp b/cell.cpp index 8bb3c3d7..e791ab06 100644 --- a/cell.cpp +++ b/cell.cpp @@ -378,9 +378,9 @@ EX void clearfrom(heptagon *at) { q.pop(); DEBB(DF_MEMORY, ("from %p", at)); if(!at->c7) { - heptagon *h = (heptagon*) at->cdata; + heptagon *h = dynamic_cast ((cdata_or_heptagon*) at->cdata); if(h) { - if(h->alt != at) { DEBB(DF_MEMORY | DF_ERROR, ("alt error :: h->alt = ", h->alt)); } + if(h->alt != at) { DEBB(DF_MEMORY | DF_ERROR, ("alt error :: h->alt = ", h->alt, " expected ", at)); } cell *c = h->c7; subcell(c, destroycellcontents); h->alt = NULL; diff --git a/locations.cpp b/locations.cpp index 16d3673e..e4f564a3 100644 --- a/locations.cpp +++ b/locations.cpp @@ -287,7 +287,9 @@ enum hstate { hsOrigin, hsA, hsB, hsError, hsA0, hsA1, hsB0, hsB1, hsC }; struct cell *createMov(struct cell *c, int d); struct heptagon *createStep(struct heptagon *c, int d); -struct cdata { +struct cdata_or_heptagon { virtual ~cdata_or_heptagon() {} }; + +struct cdata : cdata_or_heptagon { int val[4]; int bits; }; @@ -313,7 +315,7 @@ constexpr int iteration_limit = 10000000; * heptagons are unused */ -struct heptagon { +struct heptagon : cdata_or_heptagon { /** \brief Automata are used to generate the standard maps. s is the state of this automaton */ hstate s : 6; /** \brief distance modulo 4, in heptagons */