summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorNathan Binkert <nate@binkert.org>2011-04-20 19:07:46 -0700
committerNathan Binkert <nate@binkert.org>2011-04-20 19:07:46 -0700
commit2342aa2ebbb9dfe232eafcd20f01a8dd95ebfcc0 (patch)
treec8ab2aa6f02b989406ab777ef3b4b38ff894263a /src/base
parent6e9143d36de89ec03ea8b183200a622cf494c010 (diff)
downloadgem5-2342aa2ebbb9dfe232eafcd20f01a8dd95ebfcc0.tar.xz
stats: ensure that stat names are valid
Diffstat (limited to 'src/base')
-rw-r--r--src/base/statistics.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/base/statistics.cc b/src/base/statistics.cc
index 8bbc4bf36..f1a368f47 100644
--- a/src/base/statistics.cc
+++ b/src/base/statistics.cc
@@ -138,9 +138,43 @@ Info::~Info()
{
}
+bool
+validateStatName(const string &name)
+{
+ if (name.empty())
+ return false;
+
+ vector<string> vec;
+ tokenize(vec, name, '.');
+ vector<string>::const_iterator item = vec.begin();
+ while (item != vec.end()) {
+ if (item->empty())
+ return false;
+
+ string::const_iterator c = item->begin();
+
+ // The first character is different
+ if (!isalpha(*c) && *c != '_')
+ return false;
+
+ // The rest of the characters have different rules.
+ while (++c != item->end()) {
+ if (!isalnum(*c) && *c != '_')
+ return false;
+ }
+
+ ++item;
+ }
+
+ return true;
+}
+
void
Info::setName(const string &name)
{
+ if (!validateStatName(name))
+ panic("invalid stat name '%s'", name);
+
pair<NameMapType::iterator, bool> p =
nameMap().insert(make_pair(name, this));