summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-12 03:06:15 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-12 03:06:15 -0400
commitdc68903bb219c3fdaa17e2aa78a7ee5edfd74f0b (patch)
tree4c6d2527d2d83e3e3102dc5f3c8c278b73c96784
parenteaac95147c91c1bb425e8a71e35bcf7d3c3aaf9d (diff)
downloadfork-ledger-dc68903bb219c3fdaa17e2aa78a7ee5edfd74f0b.tar.gz
fork-ledger-dc68903bb219c3fdaa17e2aa78a7ee5edfd74f0b.tar.bz2
fork-ledger-dc68903bb219c3fdaa17e2aa78a7ee5edfd74f0b.zip
Added validation code for mask_t objects.
-rw-r--r--src/mask.cc1
-rw-r--r--src/mask.h11
-rw-r--r--src/value.h2
3 files changed, 14 insertions, 0 deletions
diff --git a/src/mask.cc b/src/mask.cc
index ed422b91..bf45e6f5 100644
--- a/src/mask.cc
+++ b/src/mask.cc
@@ -42,6 +42,7 @@ mask_t::mask_t(const string& pat) : expr()
mask_t& mask_t::operator=(const string& pat)
{
expr.assign(pat.c_str(), regex::perl | regex::icase);
+ VERIFY(valid());
return *this;
}
diff --git a/src/mask.h b/src/mask.h
index 6b17cf61..065d06a2 100644
--- a/src/mask.h
+++ b/src/mask.h
@@ -77,12 +77,23 @@ public:
}
bool match(const string& str) const {
+ DEBUG("mask.match",
+ "Matching: \"" << str << "\" =~ /" << expr.str() << "/ = "
+ << (boost::regex_search(str, expr) ? "true" : "false"));
return boost::regex_search(str, expr);
}
bool empty() const {
return expr.empty();
}
+
+ bool valid() const {
+ if (expr.status() != 0) {
+ DEBUG("ledger.validate", "mask_t: expr.status() != 0");
+ return false;
+ }
+ return true;
+ }
};
inline std::ostream& operator<<(std::ostream& out, const mask_t& mask) {
diff --git a/src/value.h b/src/value.h
index e98d74cb..7b058065 100644
--- a/src/value.h
+++ b/src/value.h
@@ -622,10 +622,12 @@ public:
mask_t& as_mask_lval() {
assert(is_mask());
_dup();
+ VERIFY(boost::get<mask_t>(storage->data).valid());
return boost::get<mask_t>(storage->data);
}
const mask_t& as_mask() const {
assert(is_mask());
+ VERIFY(boost::get<mask_t>(storage->data).valid());
return boost::get<mask_t>(storage->data);
}
void set_mask(const string& val) {