about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-09-12 14:39:20 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-09-12 14:39:20 -0700
commit7be15b8b4ac500face0c01294cad28c489dfcfbf (patch)
tree06284ec0a987efd6d7cfc8e87d2f2ec0e5481d4e
parentfa94f4d92340f001560b16dd0c2e5681ca5db031 (diff)
downloadmu-7be15b8b4ac500face0c01294cad28c489dfcfbf.tar.gz
2184 - bugfix in trace_count
It was reading lines like this in scenarios:

  -warn: f: error error

as:

  -warn: f

which was causing them to be silently ignored.

Also found an insane preprocessor expansion from not parenthesizing
preprocessor arguments. SIZE(end+delim) worked even when end was an
integer, but it happily didn't ever get the wrong answer.
-rw-r--r--001help.cc2
-rw-r--r--003trace.cc13
2 files changed, 12 insertions, 3 deletions
diff --git a/001help.cc b/001help.cc
index 24df0f29..3fb7b905 100644
--- a/001help.cc
+++ b/001help.cc
@@ -78,7 +78,7 @@ bool is_equal(char* s, const char* lit) {
 // yadda-yadda. Instead use this macro below to perform an unsafe cast to
 // signed. We'll just give up immediately if a container's every too large.
 :(before "End Includes")
-#define SIZE(X) (assert(X.size() < (1LL<<(sizeof(long long int)*8-2))), static_cast<long long int>(X.size()))
+#define SIZE(X) (assert((X).size() < (1LL<<(sizeof(long long int)*8-2))), static_cast<long long int>((X).size()))
 //
 // 5. Integer overflow is still impossible to guard against. Maybe after
 // reading http://www.cs.utah.edu/~regehr/papers/overflow12.pdf
diff --git a/003trace.cc b/003trace.cc
index 4426bbd3..00764d4f 100644
--- a/003trace.cc
+++ b/003trace.cc
@@ -278,7 +278,7 @@ bool trace_doesnt_contain(string layer, string line) {
 }
 
 bool trace_doesnt_contain(string expected) {
-  vector<string> tmp = split(expected, ": ");
+  vector<string> tmp = split_first(expected, ": ");
   return trace_doesnt_contain(tmp.at(0), tmp.at(1));
 }
 
@@ -295,12 +295,21 @@ vector<string> split(string s, string delim) {
       break;
     }
     result.push_back(string(s, begin, end-begin));
-    begin = SIZE(end+delim);
+    begin = end+SIZE(delim);
     end = s.find(delim, begin);
   }
   return result;
 }
 
+vector<string> split_first(string s, string delim) {
+  vector<string> result;
+  size_t end=s.find(delim);
+  result.push_back(string(s, 0, end));
+  if (end != string::npos)
+    result.push_back(string(s, end+SIZE(delim), string::npos));
+  return result;
+}
+
 string trim(const string& s) {
   string::const_iterator first = s.begin();
   while (first != s.end() && isspace(*first))