From 6225fd38e8a9f3d35743c8be54e3b6273a9f2445 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 17 Jul 2022 12:42:35 +0200 Subject: [PATCH] savemem:: removed some more potential crashes --- attack.cpp | 2 +- complex.cpp | 2 ++ graph.cpp | 2 +- monstermove.cpp | 5 +++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/attack.cpp b/attack.cpp index c768afe9..6c9447a5 100644 --- a/attack.cpp +++ b/attack.cpp @@ -454,7 +454,7 @@ EX void killMutantIvy(cell *c, eMonster who) { changes.ccell(c); removeIvy(c); for(int i=0; itype; i++) - if(c->move(i)->mondir == c->c.spin(i) && (isMutantIvy(c->move(i)) || c->move(i)->monst == moFriendlyIvy)) + if(c->move(i) && c->move(i)->mondir == c->c.spin(i) && (isMutantIvy(c->move(i)) || c->move(i)->monst == moFriendlyIvy)) kills[c->move(i)->monst]++, killMutantIvy(c->move(i), who); if(c->land == laClearing) clearing::imput(c); } diff --git a/complex.cpp b/complex.cpp index 4436e853..ba9a7873 100644 --- a/complex.cpp +++ b/complex.cpp @@ -2709,6 +2709,7 @@ EX namespace dragon { total += c->hitpoints; if(c->mondir == NODIR) return total; c = c->move(c->mondir); + if(!c) return total; } return total; } @@ -2737,6 +2738,7 @@ EX namespace dragon { } while(c->mondir != NODIR) { c = c->move(c->mondir); + if(!c) return; c->stuntime = 2; } break; diff --git a/graph.cpp b/graph.cpp index fd39a815..ae91dc8a 100644 --- a/graph.cpp +++ b/graph.cpp @@ -2539,7 +2539,7 @@ EX int cellcolor(cell *c) { int taildist(cell *c) { int s = 0; - while(s < 1000 && c->mondir != NODIR && isWorm(c->monst)) { + while(s < 1000 && c && c->mondir != NODIR && isWorm(c->monst)) { s++; c = c->move(c->mondir); } return s; diff --git a/monstermove.cpp b/monstermove.cpp index 737c5a40..57b8b658 100644 --- a/monstermove.cpp +++ b/monstermove.cpp @@ -817,6 +817,7 @@ EX void moveWorm(cell *c) { while(c2->mondir != NODIR) { allcells.push_back(c2); c2 = c2->move(c2->mondir); + if(!c2) { allcells.pop_back(); break; } } allcells.push_back(c2); for(int i=isize(allcells)-2; i>=0; i--) { @@ -865,7 +866,7 @@ EX void moveWorm(cell *c) { } eItem loc = treasureType(c->land); bool spiceSeen = false; - while(c->monst == moWorm || c->monst == moWormtail || c->monst == moTentacle || c->monst == moTentacletail) { + while(c && (c->monst == moWorm || c->monst == moWormtail || c->monst == moTentacle || c->monst == moTentacletail)) { // if(!id) explodeAround(c); drawParticles(c, minf[c->monst].color, 16); @@ -981,7 +982,7 @@ EX void removeIvy(cell *c) { c->monst = moNone; // NEWYEARFIX for(int i=0; itype; i++) // note that semi-vines don't count - if(c->move(i)->wall == waVinePlant) { + if(c->move(i) && c->move(i)->wall == waVinePlant) { destroyHalfvine(c); if (!do_not_touch_this_wall(c)) c->wall = waVinePlant;