blob: 2e60e4f263881f33787a960888c55f0d13cfc4ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
--- src/config.cpp
+++ src/config.cpp
@@ -175,24 +175,26 @@
std::istringstream iss(line);
std::string id, eq, val;
- bool error = false;
-
- if (!(iss >> id)) {
- continue;
- } else if (id[0] == '#') {
+ iss >> id;
+ if (iss.fail()) {
continue;
} else if (id.empty()) {
continue;
- } else if (!(iss >> eq >> val >> std::ws) || eq != "=" || iss.get() != EOF) {
- error = true;
+ } else if (id[0] == '#') {
+ continue;
}
- 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;
}
|