diff --git a/src/bufr_keys_iterator.c b/src/bufr_keys_iterator.c index a6422da9b..2c4177943 100644 --- a/src/bufr_keys_iterator.c +++ b/src/bufr_keys_iterator.c @@ -62,7 +62,7 @@ static void mark_seen(grib_keys_iterator* ki,const char* name) if (r) (*r)++; else { - r=grib_context_malloc(ki->handle->context,sizeof(int)); + r=(int*)grib_context_malloc(ki->handle->context,sizeof(int)); *r=1; grib_trie_insert(ki->seen,name,(void*)r); } @@ -121,7 +121,7 @@ static int next_attribute(grib_keys_iterator* kiter) if (kiter->attributes[kiter->i_curr_attribute]) { if (!kiter->prefix) { - kiter->prefix=grib_context_malloc_clear(kiter->current->context,strlen(kiter->current->name)+10); + kiter->prefix=(char*)grib_context_malloc_clear(kiter->current->context,strlen(kiter->current->name)+10); r=(int*)grib_trie_get(kiter->seen,kiter->current->name); sprintf(kiter->prefix,"#%d#%s",*r,kiter->current->name); } @@ -134,7 +134,7 @@ static int next_attribute(grib_keys_iterator* kiter) kiter->prefix=0; return 0; } - prefix=grib_context_malloc_clear(kiter->current->context,strlen(kiter->prefix)+strlen(kiter->attributes[i_curr_attribute]->name)+3); + prefix=(char*)grib_context_malloc_clear(kiter->current->context,strlen(kiter->prefix)+strlen(kiter->attributes[i_curr_attribute]->name)+3); sprintf(prefix,"%s->%s",kiter->prefix,kiter->attributes[i_curr_attribute]->name); grib_context_free(kiter->current->context,kiter->prefix); kiter->prefix=prefix; @@ -184,10 +184,10 @@ char* codes_bufr_keys_iterator_get_name(grib_keys_iterator* kiter) if (kiter->prefix) { int iattribute=kiter->i_curr_attribute-1; - ret=grib_context_malloc_clear(kiter->handle->context,strlen(kiter->prefix)+strlen(kiter->attributes[iattribute]->name)+10); + ret=(char*)grib_context_malloc_clear(kiter->handle->context,strlen(kiter->prefix)+strlen(kiter->attributes[iattribute]->name)+10); sprintf(ret,"%s->%s",kiter->prefix,kiter->attributes[iattribute]->name); } else { - ret=grib_context_malloc_clear(kiter->handle->context,strlen(kiter->current->name)+10); + ret=(char*)grib_context_malloc_clear(kiter->handle->context,strlen(kiter->current->name)+10); if (kiter->current->flags & GRIB_ACCESSOR_FLAG_BUFR_DATA) { r=(int*)grib_trie_get(kiter->seen,kiter->current->name); diff --git a/src/bufr_util.c b/src/bufr_util.c index 36c21638c..a0403a938 100644 --- a/src/bufr_util.c +++ b/src/bufr_util.c @@ -42,7 +42,7 @@ int compute_bufr_key_rank(grib_handle* h, grib_string_list* keys, const char* ke /* This is the first and only instance of the key */ /* So we check if there is a second one of this key, */ /* If not, then rank is zero i.e. this is the only instance */ - char* s=grib_context_malloc_clear(c,strlen(key)+5); + char* s=(char*)grib_context_malloc_clear(c,strlen(key)+5); sprintf(s,"#2#%s",key); if (grib_get_size(h,s,&size)==GRIB_NOT_FOUND) theRank=0; grib_context_free(c, s); diff --git a/src/grib_value.c b/src/grib_value.c index a65fb0571..ab69baf82 100644 --- a/src/grib_value.c +++ b/src/grib_value.c @@ -1690,77 +1690,77 @@ int grib_key_equal(grib_handle* h1,grib_handle* h2,const char* key,int type,int int codes_copy_key(grib_handle* h1,grib_handle* h2,const char* key,int type) { - double d; - double* ad; - long l; - long* al; - char* s=0; - char** as=0; - size_t len1,len; - int err=0; + double d; + double* ad; + long l; + long* al; + char* s=0; + char** as=0; + size_t len1,len; + int err=0; - if ( type != GRIB_TYPE_DOUBLE && - type != GRIB_TYPE_LONG && - type != GRIB_TYPE_STRING ) { - err=grib_get_native_type(h1,key,&type); + if ( type != GRIB_TYPE_DOUBLE && + type != GRIB_TYPE_LONG && + type != GRIB_TYPE_STRING ) { + err=grib_get_native_type(h1,key,&type); + if (err) return err; + } + + err=grib_get_size(h1,key,&len1); if (err) return err; - } - err=grib_get_size(h1,key,&len1); - if (err) return err; - - switch (type) { + switch (type) { case GRIB_TYPE_DOUBLE: - if (len1==1) { - err=grib_get_double(h1,key,&d); - if (err) return err; - grib_context_log(h1->context,GRIB_LOG_DEBUG,"codes_copy_key: %s=%g\n",key,d); - err=grib_set_double(h2,key,d); - return err; - } else { - ad=grib_context_malloc_clear(h1->context,len1*sizeof(double)); - err=grib_get_double_array(h1,key,ad,&len1); - if (err) return err; - err=grib_set_double_array(h2,key,ad,len1); - grib_context_free(h1->context,ad); - return err; - } - break; + if (len1==1) { + err=grib_get_double(h1,key,&d); + if (err) return err; + grib_context_log(h1->context,GRIB_LOG_DEBUG,"codes_copy_key: %s=%g\n",key,d); + err=grib_set_double(h2,key,d); + return err; + } else { + ad=(double*)grib_context_malloc_clear(h1->context,len1*sizeof(double)); + err=grib_get_double_array(h1,key,ad,&len1); + if (err) return err; + err=grib_set_double_array(h2,key,ad,len1); + grib_context_free(h1->context,ad); + return err; + } + break; case GRIB_TYPE_LONG: - if (len1==1) { - err=grib_get_long(h1,key,&l); - if (err) return err; - grib_context_log(h1->context,GRIB_LOG_DEBUG,"codes_copy_key: %s=%ld\n",key,l); - err=grib_set_long(h2,key,l); - return err; - } else { - al=grib_context_malloc_clear(h1->context,len1*sizeof(long)); - err=grib_get_long_array(h1,key,al,&len1); - if (err) return err; - err=grib_set_long_array(h2,key,al,len1); - grib_context_free(h1->context,al); - return err; - } - break; + if (len1==1) { + err=grib_get_long(h1,key,&l); + if (err) return err; + grib_context_log(h1->context,GRIB_LOG_DEBUG,"codes_copy_key: %s=%ld\n",key,l); + err=grib_set_long(h2,key,l); + return err; + } else { + al=(long*)grib_context_malloc_clear(h1->context,len1*sizeof(long)); + err=grib_get_long_array(h1,key,al,&len1); + if (err) return err; + err=grib_set_long_array(h2,key,al,len1); + grib_context_free(h1->context,al); + return err; + } + break; case GRIB_TYPE_STRING: - err=grib_get_string_length(h1,key,&len); - if (len1==1) { - s=grib_context_malloc_clear(h1->context,len); - err=grib_get_string(h1,key,s,&len); - if (err) return err; - grib_context_log(h1->context,GRIB_LOG_DEBUG,"codes_copy_key: %s=%s\n",key,s); - err=grib_set_string(h2,key,s,&len); - grib_context_free(h1->context,s); - return err; - } else { - as=grib_context_malloc_clear(h1->context,len1*sizeof(char*)); - err=grib_get_string_array(h1,key,as,&len1); - if (err) return err; - err=grib_set_string_array(h2,key,(const char **)as,len1); - return err; - } - break; + err=grib_get_string_length(h1,key,&len); + if (len1==1) { + s=(char*)grib_context_malloc_clear(h1->context,len); + err=grib_get_string(h1,key,s,&len); + if (err) return err; + grib_context_log(h1->context,GRIB_LOG_DEBUG,"codes_copy_key: %s=%s\n",key,s); + err=grib_set_string(h2,key,s,&len); + grib_context_free(h1->context,s); + return err; + } else { + as=(char**)grib_context_malloc_clear(h1->context,len1*sizeof(char*)); + err=grib_get_string_array(h1,key,as,&len1); + if (err) return err; + err=grib_set_string_array(h2,key,(const char **)as,len1); + return err; + } + break; default: - return GRIB_INVALID_TYPE; - } + return GRIB_INVALID_TYPE; + } }