Skip to content
Snippets Groups Projects
Unverified Commit 938e6b0c authored by Clayton Craft's avatar Clayton Craft
Browse files

config: Explicitly check for bad bit when parsing config line (MR 162)

In gcc 12, the return value for the operator>> of istringstream doesn't
seem to indicate success or not, this may have been taking advantage of
some undocumented or deprecated behavior... Anyways, with this change
the bad bit is checked explicitly after expanding the line.

This also simplifies the code slightly by removing the error var, which
was not really necessary.

Fixes: #143
Replaces: !157
parent 6863e387
No related branches found
No related tags found
No related merge requests found
......@@ -191,24 +191,26 @@ bool Config::Parse(std::istream &file)
std::istringstream iss(line);
std::string id, eq, val;
bool error = false;
if (!(iss >> id)) {
iss >> id;
if (iss.fail()) {
continue;
} else if (id.empty()) {
continue;
} else if (id[0] == '#') {
continue;
} else if (!(iss >> eq >> val >> std::ws) || eq != "=" || iss.get() != EOF) {
error = true;
}
if (error) {
iss >> eq >> val;
// check that:
// 1) fail/bad bits aren't set
// 2) eq field is '='
// 3) that there are no trailing fields, after ignoring any trailing whitespace
if (iss.fail() || eq.compare("=") || !(iss >> std::ws).eof()) {
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Syntax error on line %d", lineno);
return false;
} else {
Config::options[id] = val;
}
Config::options[id] = val;
}
return true;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment