changeset d69720504203 in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=d69720504203
description:
        stats: ensure that stat names are valid

diffstat:

 src/base/statistics.cc |  34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diffs (47 lines):

diff -r acf4b902c02e -r d69720504203 src/base/statistics.cc
--- a/src/base/statistics.cc    Wed Apr 20 19:07:45 2011 -0700
+++ b/src/base/statistics.cc    Wed Apr 20 19:07:46 2011 -0700
@@ -138,9 +138,43 @@
 {
 }
 
+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));
 
_______________________________________________
m5-dev mailing list
m5-dev@m5sim.org
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to