From 30abbdc00f3c7d1ef72d7a720538bd28f453f9c5 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 10 Apr 2018 17:02:43 +0100 Subject: [PATCH] ECC-616: BUFR operator 203YYY: implement encoding (Part 3) --- src/grib_accessor_class_bufr_data_array.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/grib_accessor_class_bufr_data_array.c b/src/grib_accessor_class_bufr_data_array.c index 02297db36..3a362e7ae 100644 --- a/src/grib_accessor_class_bufr_data_array.c +++ b/src/grib_accessor_class_bufr_data_array.c @@ -1142,8 +1142,15 @@ static int encode_new_element(grib_context* c,grib_accessor_bufr_data_array* sel /* Operator 203YYY: Change Reference Values: Encoding definition phase */ long currRefVal=-1; long numBits = self->change_ref_value_operand; - Assert( self->refValListSize > 0 ); - Assert( self->refValIndex < self->refValListSize ); + if ( self->refValListSize == 0 ) { + grib_context_log(c, GRIB_LOG_ERROR,"encode_new_element: Overridden Reference Values array is empty!"); + return GRIB_ENCODING_ERROR; + } + if ( self->refValIndex >= self->refValListSize ) { + grib_context_log(c, GRIB_LOG_ERROR,"encode_new_element: Overridden Reference Values error: index=%ld, size=%ld", + self->refValIndex, self->refValListSize); + return GRIB_ENCODING_ERROR; + } currRefVal = self->refValList[self->refValIndex]; grib_context_log(c,GRIB_LOG_DEBUG, "encode_new_element: Operator 203YYY: writing ref val %ld (self->refValIndex=%ld)", currRefVal, self->refValIndex); @@ -1263,8 +1270,15 @@ static int encode_element(grib_context* c,grib_accessor_bufr_data_array* self,in /* Operator 203YYY: Change Reference Values: Encoding definition phase */ long currRefVal=-1; long numBits = self->change_ref_value_operand; - Assert( self->refValListSize > 0 ); - Assert( self->refValIndex < self->refValListSize ); + if ( self->refValListSize == 0 ) { + grib_context_log(c, GRIB_LOG_ERROR,"encode_new_element: Overridden Reference Values array is empty!"); + return GRIB_ENCODING_ERROR; + } + if ( self->refValIndex >= self->refValListSize ) { + grib_context_log(c, GRIB_LOG_ERROR,"encode_new_element: Overridden Reference Values error: index=%ld, size=%ld", + self->refValIndex, self->refValListSize); + return GRIB_ENCODING_ERROR; + } currRefVal = self->refValList[self->refValIndex]; grib_context_log(c,GRIB_LOG_DEBUG, "encode_element: Operator 203YYY: writing ref val %ld (self->refValIndex=%ld)", currRefVal, self->refValIndex);