Skip to content

Commit 7189f3d

Browse files
author
Rafał Hibner
committed
Enum value checker
1 parent 00d8878 commit 7189f3d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/SchemaGenerator.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,8 +1322,16 @@ service::AwaitableResolver Result<)cpp"
13221322
{
13231323
response::Value result(response::Type::EnumValue);
13241324
1325+
const size_t idx = static_cast<size_t>(value);
1326+
if (idx<0 || idx >= s_names)cpp"
1327+
<< enumType.cppType << R"cpp(.size())
1328+
{
1329+
throw service::schema_exception { { R"ex(Enum value out of range for )cpp"
1330+
<< enumType.type << R"cpp()ex" } };
1331+
}
1332+
13251333
result.set<std::string>(std::string { s_names)cpp"
1326-
<< enumType.cppType << R"cpp([static_cast<size_t>(value)] });
1334+
<< enumType.cppType << R"cpp([idx] });
13271335
13281336
return result;
13291337
});

0 commit comments

Comments
 (0)