Fix cppcheck warnings

This commit is contained in:
Shahram Najm 2021-10-24 16:44:53 +01:00
parent 988951c20a
commit bfd97b3e8c
15 changed files with 44 additions and 39 deletions

View File

@ -225,7 +225,7 @@ static int unpack_long(grib_accessor* a, long* v, size_t* len)
return err; return err;
i = 0; i = 0;
while (val[i] == ' ' && val[i] != 0 && i < l - 1) while (i < l - 1 && val[i] == ' ')
i++; i++;
if (val[i] == 0) { if (val[i] == 0) {

View File

@ -1838,8 +1838,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
size = (lengthOfSecondOrderValues + 7) / 8; size = (lengthOfSecondOrderValues + 7) / 8;
sizebits = lengthOfSecondOrderValues; sizebits = lengthOfSecondOrderValues;
/* padding section 4 to an even number of octets*/ /* padding section 4 to an even number of octets */
size = (size + offsetBeforeData - offsetSection4) % 2 ? size + 1 : size; size = ((size + offsetBeforeData - offsetSection4) % 2) ? size + 1 : size;
half_byte = 8 * size - sizebits; half_byte = 8 * size - sizebits;
if ((ret = grib_set_long_internal(handle, self->half_byte, half_byte)) != GRIB_SUCCESS) if ((ret = grib_set_long_internal(handle, self->half_byte, half_byte)) != GRIB_SUCCESS)
return ret; return ret;

View File

@ -219,8 +219,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
double* values = (double*)val; double* values = (double*)val;
size_t inlen = *len; size_t inlen = *len;
int free_buffer = 0; /*int free_buffer = 0;
int free_values = 0; *int free_values = 0;*/
int code = GRIB_SUCCESS; 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); code = grib_ieee_encode_array(a->context, values, inlen, bytes, buffer);
clean_up: clean_up:
if (free_buffer) /*if (free_buffer)
free(buffer); * free(buffer);
if (free_values) * if (free_values)
free(values); * free(values);
*/
grib_buffer_replace(a, buffer, bufsize, 1, 1); grib_buffer_replace(a, buffer, bufsize, 1, 1);

View File

@ -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_accessor_data_simple_packing* self = (grib_accessor_data_simple_packing*)a;
grib_handle* gh = grib_handle_of_accessor(a); grib_handle* gh = grib_handle_of_accessor(a);
size_t i; size_t i = 0;
size_t n_vals = *len; size_t n_vals = *len;
int err = 0; int err = 0;
int last; int last;

View File

@ -248,7 +248,7 @@ static int unpack_long(grib_accessor* a, long* v, size_t* len)
return err; return err;
i = 0; i = 0;
while (val[i] == ' ' && val[i] != 0 && i < l - 1) while (i < l - 1 && val[i] == ' ')
i++; i++;
if (val[i] == 0) { if (val[i] == 0) {

View File

@ -223,7 +223,7 @@ static int unpack_long(grib_accessor* a, long* v, size_t* len)
return err; return err;
i = 0; i = 0;
while (i < l - 1 && val[i] == ' ' && val[i] != 0) while (i < l - 1 && val[i] == ' ')
i++; i++;
if (val[i] == 0) { if (val[i] == 0) {

View File

@ -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);*/ /* printf("EVEN %ld %ld\n",(long) a->offset,(long) offset);*/
seclen = a->offset - 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) static void init(grib_accessor* a, const long len, grib_arguments* args)

View File

@ -176,14 +176,13 @@ int grib_encode_signed_longb(unsigned char* p, long val, long* bitp, long nb)
Assert(nb <= max_nbits); Assert(nb <= max_nbits);
if (sign) if (sign) {
val = -val; val = -val;
if (sign)
grib_set_bit_on(p, bitp); grib_set_bit_on(p, bitp);
else }
else {
grib_set_bit_off(p, bitp); grib_set_bit_off(p, bitp);
}
return grib_encode_unsigned_longb(p, val, bitp, nb - 1); return grib_encode_unsigned_longb(p, val, bitp, nb - 1);
} }

View File

@ -17,7 +17,7 @@ int grib_decode_long_array(const unsigned char* p, long* bitp, long nbits, size_
{ {
long i = 0; long i = 0;
long countOfLeftmostBits = 0, leftmostBits = 0; long countOfLeftmostBits = 0, leftmostBits = 0;
long startBit, startByte; long startBit;
long remainingBits = nbits; long remainingBits = nbits;
long* pp = (long*)p; long* pp = (long*)p;
int inited = 0; 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 i = 0;
long countOfLeftmostBits = 0, leftmostBits = 0; long countOfLeftmostBits = 0, leftmostBits = 0;
long startBit, startByte; long startBit;
long remainingBits = nbits; long remainingBits = nbits;
long* pp = (long*)p; long* pp = (long*)p;
int inited = 0; int inited = 0;

View File

@ -44,9 +44,9 @@ static grib_handle* handle_of(grib_accessor* observed)
void grib_dependency_add(grib_accessor* observer, grib_accessor* observed) void grib_dependency_add(grib_accessor* observer, grib_accessor* observed)
{ {
grib_handle* h = handle_of(observed); grib_handle* h = NULL;
grib_dependency* d = h->dependencies; grib_dependency* d = NULL;
grib_dependency* last = 0; grib_dependency* last = NULL;
/*printf("grib_dependency_add: observe %p %p observed=%s observer=%s\n", /*printf("grib_dependency_add: observe %p %p observed=%s observer=%s\n",
(void*)observed, (void*)observer, (void*)observed, (void*)observer,
@ -56,6 +56,8 @@ void grib_dependency_add(grib_accessor* observer, grib_accessor* observed)
if (!observer || !observed) { if (!observer || !observed) {
return; return;
} }
h = handle_of(observed);
d = h->dependencies;
/* Assert(h == handle_of(observer)); */ /* 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) void grib_dependency_remove_observer(grib_accessor* observer)
{ {
grib_handle* h = handle_of(observer); grib_handle* h = NULL;
grib_dependency* d = h->dependencies; grib_dependency* d = NULL;
if (!observer) if (!observer)
return; return;
h = handle_of(observer);
d = h->dependencies;
while (d) { while (d) {
if (d->observer == observer) { if (d->observer == observer) {
d->observer = 0; d->observer = 0;

View File

@ -110,6 +110,7 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b)
return (*a == 0 && *b == 0) ? 0 : 1; return (*a == 0 && *b == 0) ? 0 : 1;
} }
/*
typedef struct string_count string_count; typedef struct string_count string_count;
struct string_count struct string_count
{ {
@ -117,6 +118,7 @@ struct string_count
int count; int count;
string_count* next; string_count* next;
}; };
*/
static int depth = 0; static int depth = 0;

View File

@ -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]); fprintf(self->dumper.out, " \"%s\" /)\n", values[size - 1]);
if (self->isLeaf == 0) { if (self->isLeaf == 0) {
char* prefix;
int dofree = 0;
if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 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); fprintf(self->dumper.out, " call codes_set_string_array(ibufr,'#%d#%s',svalues)\n", r, a->name);
else else
fprintf(self->dumper.out, " call codes_set_string_array(ibufr,'%s',svalues)\n", a->name); 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) { if (r != 0) {
prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10));

View File

@ -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]); fprintf(self->dumper.out, " \"%s\", )\n", values[i]);
if (self->isLeaf == 0) { if (self->isLeaf == 0) {
char* prefix;
int dofree = 0;
if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 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); fprintf(self->dumper.out, " codes_set_array(ibufr, '#%d#%s', svalues)\n", r, a->name);
else else
fprintf(self->dumper.out, " codes_set_array(ibufr, '%s', svalues)\n", a->name); 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) { if (r != 0) {
prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10));

View File

@ -593,7 +593,7 @@ static grib_order_by* grib_fieldset_new_order_by(grib_context* c, const char* ob
p++; p++;
mode = mode_default; mode = mode_default;
if (p != t2) { if (p != t2) {
while (*p == ' ' && *p != '\0') while (*p == ' ')
p++; p++;
if (*p != '\0') { if (*p != '\0') {
*(p - 1) = '\0'; *(p - 1) = '\0';
@ -683,12 +683,12 @@ int grib_fieldset_add(grib_fieldset* set, char* filename)
return ret; return ret;
} }
offset = 0; 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] = (grib_field*)grib_context_malloc_clear(c, sizeof(grib_field));
set->fields[set->size]->file = file; set->fields[set->size]->file = file;
file->refcount++; file->refcount++;
set->fields[set->size]->offset = (off_t)offset; 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->fields[set->size]->length = length;
set->filter->el[set->size] = set->size; set->filter->el[set->size] = set->size;
set->order->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) static void grib_trim(char** x)
{ {
char* p = 0; char* p = 0;
while (**x == ' ' && **x != '\0') while (**x == ' ')
(*x)++; (*x)++;
if (**x == '\0') if (**x == '\0')
return; return;

View File

@ -522,8 +522,10 @@ int grib_ieee_encode_array(grib_context* c, double* val, size_t nvals, int bytes
unsigned char* buf) unsigned char* buf)
{ {
int err = 0, i = 0, j = 0; int err = 0, i = 0, j = 0;
#if IEEE_LE
unsigned char s4[4]; unsigned char s4[4];
unsigned char s8[8]; unsigned char s8[8];
#endif
float fval = 0; float fval = 0;
double* pval = val; double* pval = val;