Skip to content

Commit 22c229f

Browse files
author
rafalh
committed
Add enum value validation
1 parent c170deb commit 22c229f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/SchemaGenerator.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1691,8 +1691,15 @@ service::AwaitableResolver Result<)cpp"
16911691
[]()cpp" << _loader.getSchemaNamespace()
16921692
<< R"cpp(::)cpp" << enumType.cppType << R"cpp( value, const ResolverParams&)
16931693
{
1694+
const size_t idx = static_cast<size_t>(value);
1695+
if (idx >= s_names)cpp"
1696+
<< enumType.cppType << R"cpp(.size())
1697+
{
1698+
throw service::schema_exception { { R"ex(Enum value out of range for )cpp"
1699+
<< enumType.type << R"cpp()ex" } };
1700+
}
16941701
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_names)cpp"
1695-
<< enumType.cppType << R"cpp([static_cast<std::size_t>(value)] } } } };
1702+
<< enumType.cppType << R"cpp([idx] } } } };
16961703
});
16971704
}
16981705

0 commit comments

Comments
 (0)