Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 5143074

Browse files
Correctly type check boolean values
Signed-off-by: Sebastian Schildt <[email protected]>
1 parent 58339a1 commit 5143074

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/VssDatabase.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jsoncons::json tryParse(jsoncons::json val) {
6565
}
6666

6767
// Check the value type and if the value is within the range
68-
void checkTypeAndBound(std::shared_ptr<ILogger> logger, string value_type, jsoncons::json val) {
68+
void checkTypeAndBound(std::shared_ptr<ILogger> logger, string value_type, jsoncons::json &val) {
6969
bool typeValid = false;
7070

7171
boost::algorithm::to_lower(value_type);
@@ -171,7 +171,6 @@ jsoncons::json tryParse(jsoncons::json val) {
171171
msg << "The type " << value_type << " with value " << val.as<float>()
172172
<< " is out of bound";
173173
logger->Log(LogLevel::ERROR, "VssDatabase::setSignal: " + msg.str());
174-
175174
throw outOfBoundException(msg.str());
176175
}
177176
} else if (value_type == "float") {
@@ -203,6 +202,22 @@ jsoncons::json tryParse(jsoncons::json val) {
203202
throw outOfBoundException(msg.str());
204203
}
205204
} else if (value_type == "boolean") {
205+
string v=val.as<string>();
206+
boost::algorithm::erase_all(v, "\"");
207+
208+
if ( v == "true") {
209+
val=true;
210+
}
211+
else if ( v == "false" ) {
212+
val=false;
213+
}
214+
else {
215+
std::stringstream msg;
216+
msg << val.as_string() << " is not a bool. Valid values are true and false ";
217+
logger->Log(LogLevel::ERROR, "VssDatabase::setSignal: " + msg.str());
218+
std::cout << pretty_print(val) << std::endl;
219+
throw outOfBoundException(msg.str());
220+
}
206221
typeValid = true;
207222
} else if (value_type == "string") {
208223
typeValid = true;

0 commit comments

Comments
 (0)