Str may be empty after .find_first_not_of(" \t\r,") and the following Str[0] accesses invalid memory.
Details
Details
Diff Detail
Diff Detail
Event Timeline
Comment Actions
It looks like substr accepts npos as a start and returns the empty string
/ \param Start The index of the starting character in the substring; if
/ the index is npos or greater than the length of the string then the
/// empty substring will be returned.
Comment Actions
I find the code a bit hard to read as written.
can we rewrite it to be just a series of "if (not interesting) { eat; continue to see if there is more;}"? Something like
static bool SkipToToken(StringRef &Str) {
for (;;) { if (Str.empty()) return false; // Strip horizontal whitespace and commas. if (size_t Pos = Str.find_first_not_of(" \t\r,")) { Str = Str.substr(Pos); continue; } if (Str[0] == '#') { Str = Str.substr(Str.find_first_of('\n')); continue; } if (Str[0] == '\n') { Str = Str.substr(1); continue; } return true; }
}
Comment Actions
Agreed that loop is a little difficult.
It looks like we can also move the check for '\n' in to the find_first_not_of check.