@@ -438,21 +438,19 @@ CBOR_TEST_CASE(cbor_decode_error_handling_test) {
438
438
struct aws_cbor_decoder * decoder = aws_cbor_decoder_new (allocator , invalid_cbor );
439
439
ASSERT_FAILS (aws_cbor_decoder_peek_type (decoder , & out_type ));
440
440
ASSERT_UINT_EQUALS (AWS_ERROR_INVALID_CBOR , aws_last_error ());
441
- aws_cbor_decoder_destroy (decoder );
442
441
443
442
/* 2. Empty cursor */
444
443
struct aws_byte_cursor empty = {0 };
445
- decoder = aws_cbor_decoder_new ( allocator , empty );
444
+ aws_cbor_decoder_reset_src ( decoder , empty );
446
445
ASSERT_FAILS (aws_cbor_decoder_peek_type (decoder , & out_type ));
447
446
ASSERT_UINT_EQUALS (AWS_ERROR_INVALID_CBOR , aws_last_error ());
448
- aws_cbor_decoder_destroy (decoder );
449
447
450
448
/* 3. Try get wrong type */
451
449
struct aws_cbor_encoder * encoder = aws_cbor_encoder_new (allocator );
452
450
uint64_t val = 1 ;
453
451
aws_cbor_encoder_write_uint (encoder , val );
454
452
struct aws_byte_cursor final_cursor = aws_cbor_encoder_get_encoded_data (encoder );
455
- decoder = aws_cbor_decoder_new ( allocator , final_cursor );
453
+ aws_cbor_decoder_reset_src ( decoder , final_cursor );
456
454
uint64_t out = 0 ;
457
455
ASSERT_FAILS (aws_cbor_decoder_pop_next_array_start (decoder , & out ));
458
456
ASSERT_UINT_EQUALS (AWS_ERROR_CBOR_UNEXPECTED_TYPE , aws_last_error ());
@@ -463,7 +461,6 @@ CBOR_TEST_CASE(cbor_decode_error_handling_test) {
463
461
ASSERT_FAILS (aws_cbor_decoder_consume_next_whole_data_item (decoder ));
464
462
ASSERT_FAILS (aws_cbor_decoder_peek_type (decoder , & out_type ));
465
463
ASSERT_UINT_EQUALS (AWS_ERROR_INVALID_CBOR , aws_last_error ());
466
- aws_cbor_decoder_destroy (decoder );
467
464
468
465
/* 4. Consume data items with size */
469
466
struct aws_byte_cursor val_1 = aws_byte_cursor_from_c_str ("my test" );
@@ -476,13 +473,13 @@ CBOR_TEST_CASE(cbor_decode_error_handling_test) {
476
473
aws_cbor_encoder_write_tag (encoder , AWS_CBOR_TAG_NEGATIVE_BIGNUM );
477
474
aws_cbor_encoder_write_bytes (encoder , val_1 );
478
475
final_cursor = aws_cbor_encoder_get_encoded_data (encoder );
479
- decoder = aws_cbor_decoder_new ( allocator , final_cursor );
476
+ aws_cbor_decoder_reset_src ( decoder , final_cursor );
480
477
ASSERT_SUCCESS (aws_cbor_decoder_peek_type (decoder , & out_type ));
481
478
ASSERT_UINT_EQUALS (AWS_CBOR_TYPE_MAP_START , out_type );
482
479
ASSERT_SUCCESS (aws_cbor_decoder_consume_next_whole_data_item (decoder ));
483
480
ASSERT_UINT_EQUALS (0 , aws_cbor_decoder_get_remaining_length (decoder ));
484
- aws_cbor_decoder_destroy (decoder );
485
481
482
+ aws_cbor_decoder_destroy (decoder );
486
483
aws_cbor_encoder_destroy (encoder );
487
484
aws_common_library_clean_up ();
488
485
return AWS_OP_SUCCESS ;
0 commit comments