mirror of https://github.com/ecmwf/eccodes.git
Fix cppcheck warnings
This commit is contained in:
parent
988951c20a
commit
bfd97b3e8c
|
@ -225,7 +225,7 @@ static int unpack_long(grib_accessor* a, long* v, size_t* len)
|
|||
return err;
|
||||
|
||||
i = 0;
|
||||
while (val[i] == ' ' && val[i] != 0 && i < l - 1)
|
||||
while (i < l - 1 && val[i] == ' ')
|
||||
i++;
|
||||
|
||||
if (val[i] == 0) {
|
||||
|
|
|
@ -1838,8 +1838,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
size = (lengthOfSecondOrderValues + 7) / 8;
|
||||
sizebits = lengthOfSecondOrderValues;
|
||||
|
||||
/* padding section 4 to an even number of octets*/
|
||||
size = (size + offsetBeforeData - offsetSection4) % 2 ? size + 1 : size;
|
||||
/* padding section 4 to an even number of octets */
|
||||
size = ((size + offsetBeforeData - offsetSection4) % 2) ? size + 1 : size;
|
||||
half_byte = 8 * size - sizebits;
|
||||
if ((ret = grib_set_long_internal(handle, self->half_byte, half_byte)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
|
|
@ -219,8 +219,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
double* values = (double*)val;
|
||||
size_t inlen = *len;
|
||||
|
||||
int free_buffer = 0;
|
||||
int free_values = 0;
|
||||
/*int free_buffer = 0;
|
||||
*int free_values = 0;*/
|
||||
|
||||
int code = GRIB_SUCCESS;
|
||||
|
||||
|
@ -261,10 +261,11 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
code = grib_ieee_encode_array(a->context, values, inlen, bytes, buffer);
|
||||
|
||||
clean_up:
|
||||
if (free_buffer)
|
||||
free(buffer);
|
||||
if (free_values)
|
||||
free(values);
|
||||
/*if (free_buffer)
|
||||
* free(buffer);
|
||||
* if (free_values)
|
||||
* free(values);
|
||||
*/
|
||||
|
||||
grib_buffer_replace(a, buffer, bufsize, 1, 1);
|
||||
|
||||
|
|
|
@ -532,7 +532,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
grib_accessor_data_simple_packing* self = (grib_accessor_data_simple_packing*)a;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
|
||||
size_t i;
|
||||
size_t i = 0;
|
||||
size_t n_vals = *len;
|
||||
int err = 0;
|
||||
int last;
|
||||
|
|
|
@ -248,7 +248,7 @@ static int unpack_long(grib_accessor* a, long* v, size_t* len)
|
|||
return err;
|
||||
|
||||
i = 0;
|
||||
while (val[i] == ' ' && val[i] != 0 && i < l - 1)
|
||||
while (i < l - 1 && val[i] == ' ')
|
||||
i++;
|
||||
|
||||
if (val[i] == 0) {
|
||||
|
|
|
@ -223,7 +223,7 @@ static int unpack_long(grib_accessor* a, long* v, size_t* len)
|
|||
return err;
|
||||
|
||||
i = 0;
|
||||
while (i < l - 1 && val[i] == ' ' && val[i] != 0)
|
||||
while (i < l - 1 && val[i] == ' ')
|
||||
i++;
|
||||
|
||||
if (val[i] == 0) {
|
||||
|
|
|
@ -160,7 +160,7 @@ static size_t preferred_size(grib_accessor* a, int from_handle)
|
|||
/* printf("EVEN %ld %ld\n",(long) a->offset,(long) offset);*/
|
||||
seclen = a->offset - offset;
|
||||
|
||||
return seclen % 2 ? 1 : 0;
|
||||
return (seclen % 2) ? 1 : 0;
|
||||
}
|
||||
|
||||
static void init(grib_accessor* a, const long len, grib_arguments* args)
|
||||
|
|
|
@ -176,14 +176,13 @@ int grib_encode_signed_longb(unsigned char* p, long val, long* bitp, long nb)
|
|||
|
||||
Assert(nb <= max_nbits);
|
||||
|
||||
if (sign)
|
||||
if (sign) {
|
||||
val = -val;
|
||||
|
||||
if (sign)
|
||||
grib_set_bit_on(p, bitp);
|
||||
else
|
||||
}
|
||||
else {
|
||||
grib_set_bit_off(p, bitp);
|
||||
|
||||
}
|
||||
return grib_encode_unsigned_longb(p, val, bitp, nb - 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ int grib_decode_long_array(const unsigned char* p, long* bitp, long nbits, size_
|
|||
{
|
||||
long i = 0;
|
||||
long countOfLeftmostBits = 0, leftmostBits = 0;
|
||||
long startBit, startByte;
|
||||
long startBit;
|
||||
long remainingBits = nbits;
|
||||
long* pp = (long*)p;
|
||||
int inited = 0;
|
||||
|
@ -84,7 +84,7 @@ int grib_decode_double_array(const unsigned char* p, long* bitp, long nbits, dou
|
|||
{
|
||||
long i = 0;
|
||||
long countOfLeftmostBits = 0, leftmostBits = 0;
|
||||
long startBit, startByte;
|
||||
long startBit;
|
||||
long remainingBits = nbits;
|
||||
long* pp = (long*)p;
|
||||
int inited = 0;
|
||||
|
|
|
@ -44,9 +44,9 @@ static grib_handle* handle_of(grib_accessor* observed)
|
|||
|
||||
void grib_dependency_add(grib_accessor* observer, grib_accessor* observed)
|
||||
{
|
||||
grib_handle* h = handle_of(observed);
|
||||
grib_dependency* d = h->dependencies;
|
||||
grib_dependency* last = 0;
|
||||
grib_handle* h = NULL;
|
||||
grib_dependency* d = NULL;
|
||||
grib_dependency* last = NULL;
|
||||
|
||||
/*printf("grib_dependency_add: observe %p %p observed=%s observer=%s\n",
|
||||
(void*)observed, (void*)observer,
|
||||
|
@ -56,6 +56,8 @@ void grib_dependency_add(grib_accessor* observer, grib_accessor* observed)
|
|||
if (!observer || !observed) {
|
||||
return;
|
||||
}
|
||||
h = handle_of(observed);
|
||||
d = h->dependencies;
|
||||
|
||||
/* Assert(h == handle_of(observer)); */
|
||||
|
||||
|
@ -164,12 +166,15 @@ int _grib_dependency_notify_change(grib_handle* h, grib_accessor* observed)
|
|||
|
||||
void grib_dependency_remove_observer(grib_accessor* observer)
|
||||
{
|
||||
grib_handle* h = handle_of(observer);
|
||||
grib_dependency* d = h->dependencies;
|
||||
grib_handle* h = NULL;
|
||||
grib_dependency* d = NULL;
|
||||
|
||||
if (!observer)
|
||||
return;
|
||||
|
||||
h = handle_of(observer);
|
||||
d = h->dependencies;
|
||||
|
||||
while (d) {
|
||||
if (d->observer == observer) {
|
||||
d->observer = 0;
|
||||
|
|
|
@ -110,6 +110,7 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b)
|
|||
return (*a == 0 && *b == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct string_count string_count;
|
||||
struct string_count
|
||||
{
|
||||
|
@ -117,6 +118,7 @@ struct string_count
|
|||
int count;
|
||||
string_count* next;
|
||||
};
|
||||
*/
|
||||
|
||||
static int depth = 0;
|
||||
|
||||
|
|
|
@ -704,15 +704,13 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm
|
|||
fprintf(self->dumper.out, " \"%s\" /)\n", values[size - 1]);
|
||||
|
||||
if (self->isLeaf == 0) {
|
||||
char* prefix;
|
||||
int dofree = 0;
|
||||
|
||||
if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0)
|
||||
fprintf(self->dumper.out, " call codes_set_string_array(ibufr,'#%d#%s',svalues)\n", r, a->name);
|
||||
else
|
||||
fprintf(self->dumper.out, " call codes_set_string_array(ibufr,'%s',svalues)\n", a->name);
|
||||
}
|
||||
|
||||
if (self->isLeaf == 0) {
|
||||
char* prefix;
|
||||
int dofree = 0;
|
||||
|
||||
if (r != 0) {
|
||||
prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10));
|
||||
|
|
|
@ -648,15 +648,13 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm
|
|||
fprintf(self->dumper.out, " \"%s\", )\n", values[i]);
|
||||
|
||||
if (self->isLeaf == 0) {
|
||||
char* prefix;
|
||||
int dofree = 0;
|
||||
|
||||
if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0)
|
||||
fprintf(self->dumper.out, " codes_set_array(ibufr, '#%d#%s', svalues)\n", r, a->name);
|
||||
else
|
||||
fprintf(self->dumper.out, " codes_set_array(ibufr, '%s', svalues)\n", a->name);
|
||||
}
|
||||
|
||||
if (self->isLeaf == 0) {
|
||||
char* prefix;
|
||||
int dofree = 0;
|
||||
|
||||
if (r != 0) {
|
||||
prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10));
|
||||
|
|
|
@ -593,7 +593,7 @@ static grib_order_by* grib_fieldset_new_order_by(grib_context* c, const char* ob
|
|||
p++;
|
||||
mode = mode_default;
|
||||
if (p != t2) {
|
||||
while (*p == ' ' && *p != '\0')
|
||||
while (*p == ' ')
|
||||
p++;
|
||||
if (*p != '\0') {
|
||||
*(p - 1) = '\0';
|
||||
|
@ -683,12 +683,12 @@ int grib_fieldset_add(grib_fieldset* set, char* filename)
|
|||
return ret;
|
||||
}
|
||||
offset = 0;
|
||||
ret = grib_get_double(h, "offset", &offset);
|
||||
grib_get_double(h, "offset", &offset);
|
||||
set->fields[set->size] = (grib_field*)grib_context_malloc_clear(c, sizeof(grib_field));
|
||||
set->fields[set->size]->file = file;
|
||||
file->refcount++;
|
||||
set->fields[set->size]->offset = (off_t)offset;
|
||||
ret = grib_get_long(h, "totalLength", &length);
|
||||
grib_get_long(h, "totalLength", &length);
|
||||
set->fields[set->size]->length = length;
|
||||
set->filter->el[set->size] = set->size;
|
||||
set->order->el[set->size] = set->size;
|
||||
|
@ -897,7 +897,7 @@ static void grib_fieldset_delete_fields(grib_fieldset* set)
|
|||
static void grib_trim(char** x)
|
||||
{
|
||||
char* p = 0;
|
||||
while (**x == ' ' && **x != '\0')
|
||||
while (**x == ' ')
|
||||
(*x)++;
|
||||
if (**x == '\0')
|
||||
return;
|
||||
|
|
|
@ -522,8 +522,10 @@ int grib_ieee_encode_array(grib_context* c, double* val, size_t nvals, int bytes
|
|||
unsigned char* buf)
|
||||
{
|
||||
int err = 0, i = 0, j = 0;
|
||||
#if IEEE_LE
|
||||
unsigned char s4[4];
|
||||
unsigned char s8[8];
|
||||
#endif
|
||||
float fval = 0;
|
||||
double* pval = val;
|
||||
|
||||
|
|
Loading…
Reference in New Issue