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.
This commit is contained in:
Kartik K. Agaram 2015-09-12 14:39:20 -07:00
parent fa94f4d923
commit 7be15b8b4a
2 changed files with 12 additions and 3 deletions

View File

@ -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

View File

@ -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))