ion-c
ion-c copied to clipboard
Ion binary reader reads null symbol will cause invalid state failure.
When we use the binary reader to read a NULL symbol and then call the ion_reader_read_null
api, it will fail with IERR_INVALID_STATE
.
// reproduction for amzn/ion-c#223
TEST(IonBinarySymbol, BinarySymbolIsNullAfterReadNext) {
// Wrtie binary $0
hWRITER writer = NULL;
ION_STREAM *ion_stream = NULL;
BYTE *data;
SIZE data_length;
BOOL is_binary = true;
ION_ASSERT_OK(ion_test_new_writer(&writer, &ion_stream, is_binary));
ION_ASSERT_OK(_ion_writer_binary_write_symbol_id(writer, 0));
ION_ASSERT_OK(ion_test_writer_get_bytes(writer, ion_stream, &data, &data_length));
// Read
hREADER reader = NULL;
ION_TYPE type;
ION_TYPE null_type;
ION_ASSERT_OK(ion_test_new_reader(data, data_length, &reader));
ION_ASSERT_OK(ion_reader_next(reader, &type));
ION_ASSERT_OK(ion_reader_read_null(reader, &null_type));
ION_ASSERT_OK(ion_reader_close(reader));
}