summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/render/bgfx/suppressorreader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/osd/modules/render/bgfx/suppressorreader.cpp')
-rw-r--r--src/osd/modules/render/bgfx/suppressorreader.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/osd/modules/render/bgfx/suppressorreader.cpp b/src/osd/modules/render/bgfx/suppressorreader.cpp
index ad17855c0fa..6d736a5a411 100644
--- a/src/osd/modules/render/bgfx/suppressorreader.cpp
+++ b/src/osd/modules/render/bgfx/suppressorreader.cpp
@@ -25,7 +25,10 @@ const suppressor_reader::string_to_enum suppressor_reader::COMBINE_NAMES[suppres
bgfx_suppressor* suppressor_reader::read_from_value(const Value& value, std::string prefix, std::map<std::string, bgfx_slider*>& sliders)
{
- validate_parameters(value, prefix);
+ if (!validate_parameters(value, prefix))
+ {
+ return nullptr;
+ }
std::string name = value["name"].GetString();
uint32_t condition = uint32_t(get_enum_from_value(value, "condition", bgfx_suppressor::condition_type::CONDITION_EQUAL, CONDITION_NAMES, CONDITION_COUNT));
@@ -57,6 +60,7 @@ bgfx_suppressor* suppressor_reader::read_from_value(const Value& value, std::str
if (slider_count > 1)
{
get_values(value, prefix, "value", values, slider_count);
+ if (!READER_CHECK(slider_count == value["value"].GetArray().Size(), (prefix + "Expected " + std::to_string(slider_count) + " values, got " + std::to_string(value["value"].GetArray().Size()) + "\n").c_str())) return nullptr;
for (int index = 1; index < slider_count; index++)
{
check_sliders.push_back(sliders[name + std::to_string(index)]);
@@ -70,21 +74,23 @@ bgfx_suppressor* suppressor_reader::read_from_value(const Value& value, std::str
return new bgfx_suppressor(check_sliders, condition, mode, values);
}
-void suppressor_reader::validate_parameters(const Value& value, std::string prefix)
+bool suppressor_reader::validate_parameters(const Value& value, std::string prefix)
{
- READER_ASSERT(value.HasMember("name"), (prefix + "Must have string value 'name'\n").c_str());
- READER_ASSERT(value["name"].IsString(), (prefix + "Value 'name' must be a string\n").c_str());
- READER_ASSERT(value.HasMember("value"), (prefix + "Must have numeric or array value 'value'\n").c_str());
- READER_ASSERT(value["value"].IsNumber() || value["value"].IsArray(), (prefix + "Value 'value' must be a number or array the size of the corresponding slider type\n").c_str());
+ if (!READER_CHECK(value.HasMember("name"), (prefix + "Must have string value 'name'\n").c_str())) return false;
+ if (!READER_CHECK(value["name"].IsString(), (prefix + "Value 'name' must be a string\n").c_str())) return false;
+ if (!READER_CHECK(value.HasMember("value"), (prefix + "Must have numeric or array value 'value'\n").c_str())) return false;
+ if (!READER_CHECK(value["value"].IsNumber() || value["value"].IsArray(), (prefix + "Value 'value' must be a number or array the size of the corresponding slider type\n").c_str())) return false;
+ return true;
}
-void suppressor_reader::get_values(const Value& value, std::string prefix, std::string name, int* values, const int count)
+bool suppressor_reader::get_values(const Value& value, std::string prefix, std::string name, int* values, const int count)
{
const char* name_str = name.c_str();
const Value& value_array = value[name_str];
for (UINT32 i = 0; i < value_array.Size() && i < count; i++)
{
- READER_ASSERT(value_array[i].IsInt(), (prefix + "value[" + std::to_string(i) + "] must be an integer\n").c_str());
+ if (!READER_CHECK(value_array[i].IsInt(), (prefix + "value[" + std::to_string(i) + "] must be an integer\n").c_str())) return false;
values[i] = value_array[i].GetInt();
}
+ return true;
}