Fix issues reported by cppcheck

This commit is contained in:
Shahram Najm 2014-10-07 16:29:15 +01:00
parent ea43cfe0e4
commit 62946c8ae0
4 changed files with 35 additions and 34 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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)