Skip to content

Commit

Permalink
Fix issue #235: Negative Binary Literals are Positive (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheqianh authored Apr 28, 2021
1 parent 8b1b571 commit a52407c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ionc/ion_reader_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,9 @@ iERR _ion_reader_text_read_int64(ION_READER *preader, int64_t *p_value)
FAILWITH(IERR_NULL_VALUE);
}

if (text->_value_sub_type == IST_INT_NEG_DECIMAL || text->_value_sub_type == IST_INT_NEG_HEX) {
if (text->_value_sub_type == IST_INT_NEG_DECIMAL
|| text->_value_sub_type == IST_INT_NEG_HEX
|| text->_value_sub_type == IST_INT_NEG_BINARY) {
sign = TRUE;
}

Expand Down
14 changes: 14 additions & 0 deletions test/test_ion_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,3 +706,17 @@ TEST(IonTextStruct, FailsOnFieldNameWithNoValueInMiddle) {
ION_ASSERT_OK(ion_reader_next(reader, &type));
ASSERT_EQ(IERR_INVALID_SYNTAX, ion_reader_next(reader, &type));
}

// reproduction for amzn/ion-c#235
TEST(IonTextInt, BinaryLiterals) {
const char *ion_text = "-0b100";
hREADER reader;
ION_TYPE type;
int64_t value;

ION_ASSERT_OK(ion_test_new_text_reader(ion_text, &reader));
ION_ASSERT_OK(ion_reader_next(reader, &type));
ASSERT_EQ(tid_INT, type);
ION_ASSERT_OK(ion_reader_read_int64(reader, &value));
ASSERT_EQ(-4, value);
}

0 comments on commit a52407c

Please sign in to comment.