From 3b6ca766514377af4beaebd44cc2d5d69c726c9e Mon Sep 17 00:00:00 2001 From: Eric Chen Date: Tue, 27 Apr 2021 17:22:51 -0700 Subject: [PATCH] Fix issue #235 (Negative Binary Literals are Positive) --- ionc/ion_reader_text.c | 4 +++- test/test_ion_text.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ionc/ion_reader_text.c b/ionc/ion_reader_text.c index bf9d96ee..e34cc5ba 100644 --- a/ionc/ion_reader_text.c +++ b/ionc/ion_reader_text.c @@ -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; } diff --git a/test/test_ion_text.cpp b/test/test_ion_text.cpp index 3a9a3ff5..9854fc7d 100644 --- a/test/test_ion_text.cpp +++ b/test/test_ion_text.cpp @@ -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); +}