From 62946c8ae0cbbd79c9af8daa06a81075aaff3389 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 7 Oct 2014 16:29:15 +0100 Subject: [PATCH] Fix issues reported by cppcheck --- src/grib_filepool.c | 1 + src/grib_handle.c | 6 ++-- src/grib_iarray.c | 2 +- src/grib_loader_from_array.c | 60 ++++++++++++++++++------------------ 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/grib_filepool.c b/src/grib_filepool.c index bd3441b4a..7d73b0619 100644 --- a/src/grib_filepool.c +++ b/src/grib_filepool.c @@ -258,6 +258,7 @@ void grib_file_pool_delete_file(grib_file* file) { if (prev->next==file) break; prev=prev->next; } + Assert(prev); prev->next=file->next; } diff --git a/src/grib_handle.c b/src/grib_handle.c index 7e072256c..098f1d1a4 100644 --- a/src/grib_handle.c +++ b/src/grib_handle.c @@ -792,7 +792,7 @@ grib_handle* taf_new_from_file ( grib_context* c, FILE* f,int headers_only,int * if ( !gl ) { *error = GRIB_DECODING_ERROR; - grib_context_log ( gl->context, GRIB_LOG_ERROR, "grib_handle_new_from_file : cannot create handle \n" ); + grib_context_log ( c, GRIB_LOG_ERROR, "grib_handle_new_from_file : cannot create handle \n" ); grib_context_free ( c,data ); return NULL; } @@ -833,7 +833,7 @@ grib_handle* metar_new_from_file ( grib_context* c, FILE* f,int headers_only,int if ( !gl ) { *error = GRIB_DECODING_ERROR; - grib_context_log ( gl->context, GRIB_LOG_ERROR, "grib_handle_new_from_file : cannot create handle \n" ); + grib_context_log ( c, GRIB_LOG_ERROR, "grib_handle_new_from_file : cannot create handle \n" ); grib_context_free ( c,data ); return NULL; } @@ -873,7 +873,7 @@ grib_handle* codes_new_from_file ( grib_context* c, FILE* f,int headers_only,int if ( !gl ) { *error = GRIB_DECODING_ERROR; - grib_context_log ( gl->context, GRIB_LOG_ERROR, "grib_handle_new_from_file : cannot create handle \n" ); + grib_context_log ( c, GRIB_LOG_ERROR, "grib_handle_new_from_file : cannot create handle \n" ); grib_context_free ( c,data ); return NULL; } diff --git a/src/grib_iarray.c b/src/grib_iarray.c index 6c47882c1..b9fe707d4 100644 --- a/src/grib_iarray.c +++ b/src/grib_iarray.c @@ -36,12 +36,12 @@ grib_iarray* grib_iarray_new(grib_context* c,size_t size,size_t incsize) { if (!c) c=grib_context_get_default(); v=(grib_iarray*)grib_context_malloc(c,sizeof(grib_iarray)); - v->context=c; if (!v) { grib_context_log(c,GRIB_LOG_ERROR, "grib_iarray_new unable to allocate %d bytes\n",sizeof(grib_iarray)); return NULL; } + v->context=c; v->size=size; v->n=0; v->incsize=incsize; diff --git a/src/grib_loader_from_array.c b/src/grib_loader_from_array.c index 2b15069e3..9eb2d6895 100644 --- a/src/grib_loader_from_array.c +++ b/src/grib_loader_from_array.c @@ -18,44 +18,44 @@ int grib_lookup_long_from_array(grib_context* gc,grib_loader* loader,const char* name,long* lvalue) { - char* strvalue=0; - size_t size=0; - char* pstr=NULL; - int retval; - grib_associative_array* ar; - grib_runtime_type* rt=grib_runtimetype_new(gc); - int type=0; + char* strvalue=0; + size_t size=0; + char* pstr=NULL; + int retval; + grib_associative_array* ar; + grib_runtime_type* rt=grib_runtimetype_new(gc); + int type=0; - ar=(grib_associative_array*)loader->data; + ar=(grib_associative_array*)loader->data; - if ((retval=grib_associative_array_get(ar,(char*)name,&rt)) != GRIB_ARRAY_SUCCESS) - return GRIB_NOT_FOUND; + if ((retval=grib_associative_array_get(ar,(char*)name,&rt)) != GRIB_ARRAY_SUCCESS) + return GRIB_NOT_FOUND; - grib_runtimetype_get_type(rt,&type); + grib_runtimetype_get_type(rt,&type); - switch (type) { + switch (type) { case GRIB_RUNTIMETYPE_LONG: - grib_runtimetype_get_long(rt,&lvalue,&size); - printf("lookup: getting long %ld\n",*lvalue); - break; + grib_runtimetype_get_long(rt,&lvalue,&size); + printf("lookup: getting long %ld\n",*lvalue); + break; case GRIB_RUNTIMETYPE_CHAR: - *lvalue = 0; - grib_runtimetype_get_char(rt,&strvalue,&size); - printf("lookup: getting char %s\n",strvalue); - pstr=strvalue; - while(*pstr) - { - *lvalue <<= 8; - *lvalue |= *pstr++; - } - break; + *lvalue = 0; + grib_runtimetype_get_char(rt,&strvalue,&size); + printf("lookup: getting char %s\n",strvalue); + pstr=strvalue; + while(*pstr) + { + *lvalue <<= 8; + *lvalue |= *pstr++; + } + break; default: - return GRIB_NOT_FOUND; - printf("lookup: wrong type (%d)\n",type); - break; - } + printf("lookup: wrong type (%d)\n",type); + return GRIB_NOT_FOUND; + break; + } - return GRIB_SUCCESS; + return GRIB_SUCCESS; } int grib_init_accessor_from_array(grib_loader* loader,grib_accessor* ga,grib_arguments* default_value)