From: Nathan Binkert Date: Thu, 21 Apr 2011 02:07:46 +0000 (-0700) Subject: stats: ensure that stat names are valid X-Git-Tag: stable_2012_02_02~376 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2342aa2ebbb9dfe232eafcd20f01a8dd95ebfcc0;p=gem5.git stats: ensure that stat names are valid --- 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 vec; + tokenize(vec, name, '.'); + vector::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 p = nameMap().insert(make_pair(name, this));