From 63c364652d58fc5b92cd9da628e6db164661ee4e Mon Sep 17 00:00:00 2001 From: jacob1 Date: Tue, 2 Oct 2012 18:30:02 -0400 Subject: [PATCH] prevent setting invalid types, fix setting type to "NONE", "C4", & "C5" --- src/cat/CommandInterface.cpp | 8 ++++---- src/cat/TPTScriptInterface.cpp | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cat/CommandInterface.cpp b/src/cat/CommandInterface.cpp index 240e7e46e..3ebc795e0 100644 --- a/src/cat/CommandInterface.cpp +++ b/src/cat/CommandInterface.cpp @@ -96,16 +96,16 @@ int CommandInterface::GetParticleType(std::string type) Element * elements = m->GetSimulation()->elements; // alternative names for some elements - if (strcasecmp(txt,"C4")==0) i = PT_PLEX; - else if (strcasecmp(txt,"C5")==0) i = PT_C5; - else if (strcasecmp(txt,"NONE")==0) i = PT_NONE; + if (strcasecmp(txt,"C4")==0) return PT_PLEX; + else if (strcasecmp(txt,"C5")==0) return PT_C5; + else if (strcasecmp(txt,"NONE")==0) return PT_NONE; for (i=1; i * words) if(value.GetType() == TypeNumber) newValue = ((NumberType)value).Value(); else if(value.GetType() == TypeString) + { newValue = GetParticleType(((StringType)value).Value()); + if (newValue < 0 || newValue >= PT_NUM) + throw GeneralException("Invalid element"); + } else throw GeneralException("Invalid value for assignment"); + if (property.Value() == "type" && (newValue < 0 || newValue >= PT_NUM)) + throw GeneralException("Invalid element"); if(selector.GetType() == TypePoint || selector.GetType() == TypeNumber) {