diff --git a/src/grib_expression_class_accessor.c b/src/grib_expression_class_accessor.c index 106222ad6..0a2e404ca 100644 --- a/src/grib_expression_class_accessor.c +++ b/src/grib_expression_class_accessor.c @@ -95,97 +95,96 @@ static void init_class(grib_expression_class* c) static const char* get_name(grib_expression* g) { - grib_expression_accessor* e = (grib_expression_accessor*)g; - return e->name; + grib_expression_accessor* e = (grib_expression_accessor*)g; + return e->name; } static int evaluate_long(grib_expression* g,grib_handle *h,long* result) { - grib_expression_accessor* e = (grib_expression_accessor*)g; - return grib_get_long_internal(h,e->name,result); + grib_expression_accessor* e = (grib_expression_accessor*)g; + return grib_get_long_internal(h,e->name,result); } static int evaluate_double(grib_expression *g,grib_handle *h,double* result) { - grib_expression_accessor* e = (grib_expression_accessor*)g; - return grib_get_double_internal(h,e->name,result); + grib_expression_accessor* e = (grib_expression_accessor*)g; + return grib_get_double_internal(h,e->name,result); } static string evaluate_string(grib_expression* g,grib_handle* h,char* buf,size_t* size,int* err) { - grib_expression_accessor* e = (grib_expression_accessor*)g; - char mybuf[1024]={0,}; - long start=e->start; + grib_expression_accessor* e = (grib_expression_accessor*)g; + char mybuf[1024]={0,}; + long start=e->start; - Assert(buf); - if((*err=grib_get_string_internal(h,e->name,mybuf,size)) != GRIB_SUCCESS) - return NULL; - - if (e->start<0) start+=*size; + Assert(buf); + if((*err=grib_get_string_internal(h,e->name,mybuf,size)) != GRIB_SUCCESS) + return NULL; - if (e->length != 0) { - memcpy(buf,mybuf+start,e->length); - buf[e->length]=0; - } else { - memcpy(buf,mybuf,*size); - buf[*size]=0; - } - return buf; + if (e->start<0) start+=*size; + + if (e->length != 0) { + memcpy(buf,mybuf+start,e->length); + buf[e->length]=0; + } else { + memcpy(buf,mybuf,*size); + if (*size==1024) *size = *size - 1; /* ECC-336 */ + buf[*size]=0; + } + return buf; } static void print(grib_context* c,grib_expression* g,grib_handle* f) { - grib_expression_accessor* e = (grib_expression_accessor*)g; - printf("access('%s",e->name); - if(f) - { - long s = 0; - grib_get_long(f,e->name,&s); - printf("=%ld",s); - } - printf("')"); + grib_expression_accessor* e = (grib_expression_accessor*)g; + printf("access('%s",e->name); + if(f) + { + long s = 0; + grib_get_long(f,e->name,&s); + printf("=%ld",s); + } + printf("')"); } static void destroy(grib_context* c,grib_expression* g) { - grib_expression_accessor* e = (grib_expression_accessor*)g; - grib_context_free_persistent(c,e->name); + grib_expression_accessor* e = (grib_expression_accessor*)g; + grib_context_free_persistent(c,e->name); } - static void add_dependency(grib_expression* g, grib_accessor* observer){ - grib_expression_accessor* e = (grib_expression_accessor*)g; - grib_accessor *observed = grib_find_accessor(grib_handle_of_accessor(observer),e->name); + grib_expression_accessor* e = (grib_expression_accessor*)g; + grib_accessor *observed = grib_find_accessor(grib_handle_of_accessor(observer),e->name); - if(!observed) - { - /* grib_context_log(observer->context, GRIB_LOG_ERROR, */ - /* "Error in accessor_add_dependency: cannot find [%s]", e->name); */ - /* Assert(observed); */ - return; - } + if(!observed) + { + /* grib_context_log(observer->context, GRIB_LOG_ERROR, */ + /* "Error in accessor_add_dependency: cannot find [%s]", e->name); */ + /* Assert(observed); */ + return; + } - grib_dependency_add(observer,observed); + grib_dependency_add(observer,observed); } grib_expression* new_accessor_expression(grib_context* c,const char *name,long start, size_t length) { - grib_expression_accessor* e = (grib_expression_accessor*)grib_context_malloc_clear_persistent(c,sizeof(grib_expression_accessor)); - e->base.cclass = grib_expression_class_accessor; - e->name = grib_context_strdup_persistent(c,name); - e->start = start; - e->length = length; - return (grib_expression*)e; + grib_expression_accessor* e = (grib_expression_accessor*)grib_context_malloc_clear_persistent(c,sizeof(grib_expression_accessor)); + e->base.cclass = grib_expression_class_accessor; + e->name = grib_context_strdup_persistent(c,name); + e->start = start; + e->length = length; + return (grib_expression*)e; } static int native_type(grib_expression* g,grib_handle *h) { - grib_expression_accessor* e = (grib_expression_accessor*)g; - int type = 0; - int err; - if((err=grib_get_native_type(h,e->name,&type)) != GRIB_SUCCESS) - grib_context_log(h->context, GRIB_LOG_ERROR, - "Error in native_type %s : %s", e->name,grib_get_error_message(err)); - return type; + grib_expression_accessor* e = (grib_expression_accessor*)g; + int type = 0; + int err; + if((err=grib_get_native_type(h,e->name,&type)) != GRIB_SUCCESS) + grib_context_log(h->context, GRIB_LOG_ERROR, + "Error in native_type %s : %s", e->name,grib_get_error_message(err)); + return type; } -