Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public Choice(final Node node, final PrimitiveType encodingType)
deprecated = Integer.parseInt(getAttributeValue(node, "deprecated", "0"));

// choice values are bit positions (0, 1, 2, 3, 4, etc.) from LSB to MSB
if (value.longValue() >= (encodingType.size() * 8L))
if (value.longValue() < 0 || value.longValue() >= (encodingType.size() * 8L))
{
throw new IllegalArgumentException("Choice value out of bounds: " + value.longValue());
}
Expand Down
15 changes: 15 additions & 0 deletions sbe-tool/src/test/java/uk/co/real_logic/sbe/xml/SetTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ void shouldThrowExceptionWhenValueOutOfBoundsSpecified()
parseTestXmlWithMap("/types/set", testXmlString));
}

@Test
void shouldThrowExceptionWhenNegativeValueSpecified()
{
final String testXmlString =
"<types>" +
"<set name=\"biOp\" encodingType=\"uint8\">" +
" <choice name=\"Bit0\">0</choice>" +
" <choice name=\"BitNeg\">-1</choice>" +
"</set>" +
"</types>";

assertThrows(IllegalArgumentException.class, () ->
parseTestXmlWithMap("/types/set", testXmlString));
}

@Test
void shouldHandleEncodingTypesWithNamedTypes() throws Exception
{
Expand Down
Loading