Fix errors/warnings reported by cppcheck

This commit is contained in:
Shahram Najm 2014-01-15 16:51:44 +00:00
parent f4026007b8
commit 15d1b2cd25
6 changed files with 26 additions and 23 deletions

View File

@ -101,11 +101,13 @@ static void compile(grib_action* act, grib_compiler* compiler)
fprintf(compiler->out,");\n");
}
static void remove_accessor(grib_accessor *a){
grib_section* s = a->parent;
static void remove_accessor(grib_accessor *a)
{
grib_section* s = NULL;
int id;
if (!a || !a->previous) return;
s = a->parent;
if (a->parent->h->use_trie && *(a->all_names[0]) != '_') {
id=grib_hash_keys_get_id(a->parent->h->context->keys,a->all_names[0]);

View File

@ -161,6 +161,7 @@ static int execute(grib_action* act, grib_handle *h)
ioerr = errno;
grib_context_log(act->context, (GRIB_LOG_ERROR) | (GRIB_LOG_PERROR),
"Error writing to %s", filename);
free(zeros);
return GRIB_IO_PROBLEM;
}
free(zeros);

View File

@ -748,11 +748,12 @@ static int grib_db_resize_int_array(grib_int_array* a,size_t newsize) {
return err;
}
static void grib_db_delete_int_array(grib_int_array* f) {
grib_context* c=f->context;
static void grib_db_delete_int_array(grib_int_array* f)
{
grib_context* c = NULL;
if (!f) return;
c = f->context;
grib_context_free(c,f->el);
grib_context_free(c,f);

View File

@ -736,11 +736,12 @@ static int grib_fieldset_resize_int_array(grib_int_array* a,size_t newsize) {
return err;
}
static void grib_fieldset_delete_int_array(grib_int_array* f) {
grib_context* c=f->context;
static void grib_fieldset_delete_int_array(grib_int_array* f)
{
grib_context* c = NULL;
if (!f) return;
c = f->context;
grib_context_free(c,f->el);
grib_context_free(c,f);

View File

@ -272,8 +272,8 @@ grib_handle* grib_handle_new_from_samples ( grib_context* c, const char* name )
return g;
}
int grib_write_message(grib_handle* h,const char* file,const char* mode) {
int grib_write_message(grib_handle* h,const char* file,const char* mode)
{
FILE* fh=0;
int err;
const void *buffer; size_t size;
@ -284,10 +284,14 @@ int grib_write_message(grib_handle* h,const char* file,const char* mode) {
return GRIB_IO_PROBLEM;
}
err=grib_get_message(h,&buffer,&size);
if (err) return err;
if (err) {
fclose(fh);
return err;
}
if(fwrite(buffer,1,size,fh) != size) {
perror(file);
fclose(fh);
return GRIB_IO_PROBLEM;
}
if (fclose(fh) != 0) {
@ -355,8 +359,6 @@ grib_handle* grib_handle_new_from_partial_message ( grib_context* c,void* data,
return grib_handle_create ( gl, c, data, buflen );
}
grib_handle* grib_handle_new_from_message ( grib_context* c,void* data, size_t buflen )
{
grib_handle *gl = NULL;
@ -516,7 +518,7 @@ static grib_handle* grib_handle_new_multi ( grib_context* c,unsigned char** data
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" );
return NULL;
}
@ -673,7 +675,7 @@ static grib_handle* grib_handle_new_from_file_multi ( grib_context* c, FILE* f,i
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;
}
@ -745,7 +747,7 @@ grib_handle* eccode_gts_new_from_file ( grib_context* c, FILE* f,int headers_onl
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;
}
@ -786,7 +788,7 @@ grib_handle* eccode_bufr_new_from_file ( grib_context* c, FILE* f,int headers_on
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;
}
@ -1232,7 +1234,6 @@ static void grib2_build_message ( grib_context* context,unsigned char* sections[
grib_encode_unsigned_long ( *data,msglen,&bitp,64 );
*len=msglen;
}
void grib_multi_support_on ( grib_context* c )
@ -1324,7 +1325,6 @@ static grib_multi_support* grib_get_multi_support ( grib_context* c, FILE* f )
return gm;
}
void grib_multi_support_reset ( grib_context* c )
{
grib_multi_support* gm=c->multi_support;
@ -1342,7 +1342,6 @@ void grib_multi_support_reset ( grib_context* c )
grib_context_free ( c,gm );
gm=NULL;
}
}
static grib_multi_support* grib_multi_support_new ( grib_context* c )
@ -1363,5 +1362,3 @@ static grib_multi_support* grib_multi_support_new ( grib_context* c )
return gm;
}

View File

@ -1259,10 +1259,11 @@ grib_handle* grib_index_get_handle(grib_field* field,int *err)
static int grib_index_execute(grib_index* index)
{
grib_index_key* keys=index->keys;
grib_index_key* keys = NULL;
grib_field_tree* fields;
if (!index) return GRIB_INTERNAL_ERROR;
keys = index->keys;
fields=index->fields;
index->rewind=0;