Skip to content

Commit bbc951f

Browse files
committed
fix(config): Fix regular expression handling in parse_duration
Signed-off-by: Steffen Vogel <[email protected]>
1 parent 2d73d5a commit bbc951f

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

include/villas/config_helper.hpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,17 @@ Duration parse_duration(std::string_view input) {
7070

7171
std::chrono::nanoseconds total_duration{0};
7272

73-
for (auto i = begin; i != end; ++i) {
74-
auto match = *i;
75-
auto number_str = match[1];
76-
auto unit_str = match[2];
73+
for (auto match = begin; match != end; ++match) {
74+
if (match->size() != 3) {
75+
throw RuntimeError("Invalid duration format: {}", match->str());
76+
}
77+
78+
auto number_str = match->str(1);
79+
auto unit_str = match->str(2);
7780

7881
auto it = unit_map.find(unit_str);
7982
if (it == unit_map.end()) {
80-
throw RuntimeError("Unknown duration unit: {}", unit_str.str());
83+
throw RuntimeError("Unknown duration unit: {}", unit_str);
8184
}
8285

8386
auto unit = it->second;
@@ -86,10 +89,10 @@ Duration parse_duration(std::string_view input) {
8689
try {
8790
number = std::stoul(number_str);
8891
} catch (const std::invalid_argument &e) {
89-
throw RuntimeError("Invalid number in duration: {}", match.str());
92+
throw RuntimeError("Invalid number in duration: {}", match->str());
9093
} catch (const std::out_of_range &e) {
9194
throw RuntimeError("Duration overflows maximum representable value: {}",
92-
match.str());
95+
match->str());
9396
}
9497

9598
auto duration = unit * number;
@@ -100,8 +103,7 @@ Duration parse_duration(std::string_view input) {
100103
if (unit.count() != 0 &&
101104
duration.count() / unit.count() != number) // Check for overflow.
102105
throw RuntimeError("Duration overflows maximum representable value: {}",
103-
match.str());
104-
;
106+
match->str());
105107

106108
total_duration += duration;
107109
}

0 commit comments

Comments
 (0)