diff --git a/src/grib_accessor_class_ascii.c b/src/grib_accessor_class_ascii.c index f15a3e524..7680cff74 100644 --- a/src/grib_accessor_class_ascii.c +++ b/src/grib_accessor_class_ascii.c @@ -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) { diff --git a/src/grib_accessor_class_data_g1second_order_general_extended_packing.c b/src/grib_accessor_class_data_g1second_order_general_extended_packing.c index 15afcf7a7..7293d26b3 100644 --- a/src/grib_accessor_class_data_g1second_order_general_extended_packing.c +++ b/src/grib_accessor_class_data_g1second_order_general_extended_packing.c @@ -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; diff --git a/src/grib_accessor_class_data_raw_packing.c b/src/grib_accessor_class_data_raw_packing.c index 147f0a3a3..28da01f9b 100644 --- a/src/grib_accessor_class_data_raw_packing.c +++ b/src/grib_accessor_class_data_raw_packing.c @@ -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); diff --git a/src/grib_accessor_class_data_simple_packing.c b/src/grib_accessor_class_data_simple_packing.c index e49162ab6..3a067de28 100644 --- a/src/grib_accessor_class_data_simple_packing.c +++ b/src/grib_accessor_class_data_simple_packing.c @@ -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; diff --git a/src/grib_accessor_class_group.c b/src/grib_accessor_class_group.c index 38cc9c67f..7d99ed408 100644 --- a/src/grib_accessor_class_group.c +++ b/src/grib_accessor_class_group.c @@ -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) { diff --git a/src/grib_accessor_class_non_alpha.c b/src/grib_accessor_class_non_alpha.c index 9c5b981e4..9fbf0141b 100644 --- a/src/grib_accessor_class_non_alpha.c +++ b/src/grib_accessor_class_non_alpha.c @@ -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) { diff --git a/src/grib_accessor_class_padtoeven.c b/src/grib_accessor_class_padtoeven.c index 13e9dc857..4daaab023 100644 --- a/src/grib_accessor_class_padtoeven.c +++ b/src/grib_accessor_class_padtoeven.c @@ -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) diff --git a/src/grib_bits.c b/src/grib_bits.c index c50c5fbf5..b99f8e033 100644 --- a/src/grib_bits.c +++ b/src/grib_bits.c @@ -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); } diff --git a/src/grib_bits_fast_big_endian_omp.c b/src/grib_bits_fast_big_endian_omp.c index 6bdb787d9..ec229e5a0 100644 --- a/src/grib_bits_fast_big_endian_omp.c +++ b/src/grib_bits_fast_big_endian_omp.c @@ -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; diff --git a/src/grib_dependency.c b/src/grib_dependency.c index 932c65055..5f25460d6 100644 --- a/src/grib_dependency.c +++ b/src/grib_dependency.c @@ -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; diff --git a/src/grib_dumper_class_bufr_encode_filter.c b/src/grib_dumper_class_bufr_encode_filter.c index 4e3e4aa20..f68e9f397 100644 --- a/src/grib_dumper_class_bufr_encode_filter.c +++ b/src/grib_dumper_class_bufr_encode_filter.c @@ -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; diff --git a/src/grib_dumper_class_bufr_encode_fortran.c b/src/grib_dumper_class_bufr_encode_fortran.c index 1f17ead15..0f99793dc 100644 --- a/src/grib_dumper_class_bufr_encode_fortran.c +++ b/src/grib_dumper_class_bufr_encode_fortran.c @@ -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)); diff --git a/src/grib_dumper_class_bufr_encode_python.c b/src/grib_dumper_class_bufr_encode_python.c index 9abf28a85..301e1eb70 100644 --- a/src/grib_dumper_class_bufr_encode_python.c +++ b/src/grib_dumper_class_bufr_encode_python.c @@ -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)); diff --git a/src/grib_fieldset.c b/src/grib_fieldset.c index 91e85929d..465b0b7fb 100644 --- a/src/grib_fieldset.c +++ b/src/grib_fieldset.c @@ -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; diff --git a/src/grib_ieeefloat.c b/src/grib_ieeefloat.c index 3c393110b..d7b713a24 100644 --- a/src/grib_ieeefloat.c +++ b/src/grib_ieeefloat.c @@ -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;