Skip to content

Commit 980154c

Browse files
authored
Merge pull request #4 from vadikrobot/fix_sf
fix segfault on checking arg existence
2 parents 201e2c8 + 2489225 commit 980154c

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

argparse.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,14 @@ class ArgumentParser {
119119
if (!_help) {
120120
for (auto &a : _arguments) {
121121
if (a._required) {
122-
if (_variables.find(a._name) == _variables.end()
123-
&& _variables.find(_pairs.find(a._name)->second) == _variables.end()) {
124-
throw ArgumentNotFound(a, _pairs);
122+
if (_variables.find(a._name) == _variables.end()) {
123+
// Check if a pair name does not exist. If it does exist check that
124+
// there is not a variable with that name
125+
if (_pairs.find(a._name) == _pairs.end() ||
126+
_variables.find(_pairs.find(a._name)->second) ==
127+
_variables.end()) {
128+
throw ArgumentNotFound(a, _pairs);
129+
}
125130
}
126131
}
127132
}

0 commit comments

Comments
 (0)