From 6410428715cdcffdc4727ef31ca3549d40105f00 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 14 Dec 2014 12:03:55 +0100 Subject: [PATCH] - fixed: FxPick leaked the array's content. Also did some cleanup on FxPick code. --- src/thingdef/thingdef_exp.h | 2 +- src/thingdef/thingdef_expression.cpp | 21 +++++---------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/thingdef/thingdef_exp.h b/src/thingdef/thingdef_exp.h index b53b8796b..0e03c661f 100644 --- a/src/thingdef/thingdef_exp.h +++ b/src/thingdef/thingdef_exp.h @@ -563,7 +563,7 @@ class FxPick : public FxExpression { protected: FRandom * rng; - TArray min; + TDeletingArray min; public: diff --git a/src/thingdef/thingdef_expression.cpp b/src/thingdef/thingdef_expression.cpp index dd8e0e4c9..913079bd2 100644 --- a/src/thingdef/thingdef_expression.cpp +++ b/src/thingdef/thingdef_expression.cpp @@ -1699,14 +1699,10 @@ ExpVal FxRandom::EvalExpression (AActor *self) FxPick::FxPick(FRandom * r, TArray mi, const FScriptPosition &pos) : FxExpression(pos) { - int index = 0; - int max = mi.Size(); - if (max > 0) + for (unsigned int index = 0; index < mi.Size(); index++) { - for (index = 0; index < max; index++) - min.Push(new FxIntCast(mi[index])); + min.Push(new FxIntCast(mi[index])); } - else min.Clear(); rng = r; ValueType = VAL_Int; } @@ -1719,7 +1715,6 @@ FxPick::FxPick(FRandom * r, TArray mi, const FScriptPosition &pos FxPick::~FxPick() { - min.Clear(); } //========================================================================== @@ -1730,17 +1725,11 @@ FxPick::~FxPick() FxExpression *FxPick::Resolve(FCompileContext &ctx) { - int index = 0; CHECKRESOLVED(); - int max = min.Size(); - if (max > 0) + for (unsigned int index = 0; index < min.Size(); index++) { - for (index = 0; index < max; index++) - { - RESOLVE(min[index], ctx); - ABORT(min[index]); - } - + RESOLVE(min[index], ctx); + ABORT(min[index]); } return this; };