Const correctness and cppcheck warnings

This commit is contained in:
shahramn 2024-03-15 13:16:42 +00:00
parent 9c71ac509c
commit e87675b1ae
9 changed files with 50 additions and 52 deletions

View File

@ -1524,9 +1524,9 @@ static int build_bitmap(grib_accessor_bufr_data_array* self, unsigned char* data
int i, localReference, width, bitmapEndElementsDescriptorsIndex; int i, localReference, width, bitmapEndElementsDescriptorsIndex;
long ppos, n; long ppos, n;
grib_accessor* a = (grib_accessor*)self; grib_accessor* a = (grib_accessor*)self;
grib_context* c = a->context; const grib_context* c = a->context;
bufr_descriptor** descriptors = self->expanded->v; bufr_descriptor** descriptors = self->expanded->v;
long* edi = elementsDescriptorsIndex->v; const long* edi = elementsDescriptorsIndex->v;
/* int iel=grib_iarray_used_size(elementsDescriptorsIndex)-1; */ /* int iel=grib_iarray_used_size(elementsDescriptorsIndex)-1; */
int err = 0; int err = 0;
@ -1653,9 +1653,9 @@ static int build_bitmap_new_data(grib_accessor_bufr_data_array* self, unsigned c
int i, bitmapEndElementsDescriptorsIndex; int i, bitmapEndElementsDescriptorsIndex;
long n; long n;
grib_accessor* a = (grib_accessor*)self; grib_accessor* a = (grib_accessor*)self;
grib_context* c = a->context; const grib_context* c = a->context;
bufr_descriptor** descriptors = self->expanded->v; bufr_descriptor** descriptors = self->expanded->v;
long* edi = elementsDescriptorsIndex->v; const long* edi = elementsDescriptorsIndex->v;
switch (descriptors[iBitmapOperator]->code) { switch (descriptors[iBitmapOperator]->code) {
case 222000: case 222000:

View File

@ -108,7 +108,7 @@ grib_accessor_class* grib_accessor_class_bufr_extract_subsets = &_grib_accessor_
static void get_accessors(grib_accessor* a) static void get_accessors(grib_accessor* a)
{ {
grib_accessor_bufr_extract_subsets* self = (grib_accessor_bufr_extract_subsets*)a; grib_accessor_bufr_extract_subsets* self = (grib_accessor_bufr_extract_subsets*)a;
grib_handle* h = grib_handle_of_accessor(a); const grib_handle* h = grib_handle_of_accessor(a);
if (self->packAccessor) if (self->packAccessor)
return; return;
@ -134,7 +134,6 @@ static int get_native_type(grib_accessor* a)
static int pack_long(grib_accessor* a, const long* val, size_t* len) static int pack_long(grib_accessor* a, const long* val, size_t* len)
{ {
int err = 0;
grib_accessor_bufr_extract_subsets* self = (grib_accessor_bufr_extract_subsets*)a; grib_accessor_bufr_extract_subsets* self = (grib_accessor_bufr_extract_subsets*)a;
size_t l = 1; size_t l = 1;
long v[1]; long v[1];
@ -142,7 +141,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
get_accessors(a); get_accessors(a);
v[0] = 1; v[0] = 1;
err = grib_pack_long(self->packAccessor, v, &l); int err = grib_pack_long(self->packAccessor, v, &l);
if (err) { if (err) {
if (err == GRIB_ENCODING_ERROR) if (err == GRIB_ENCODING_ERROR)
grib_context_log(a->context, GRIB_LOG_ERROR, "Could not extract subset(s).\n\tHint: Did you forget to set unpack=1?"); grib_context_log(a->context, GRIB_LOG_ERROR, "Could not extract subset(s).\n\tHint: Did you forget to set unpack=1?");

View File

@ -133,18 +133,17 @@ static int get_native_type(grib_accessor* a)
static int apply_thinning(grib_accessor* a) static int apply_thinning(grib_accessor* a)
{ {
grib_accessor_bufr_simple_thinning* self = (grib_accessor_bufr_simple_thinning*)a; const grib_accessor_bufr_simple_thinning* self = (grib_accessor_bufr_simple_thinning*)a;
int ret = 0;
long skip; long skip;
grib_handle* h = grib_handle_of_accessor(a); grib_handle* h = grib_handle_of_accessor(a);
grib_context* c = h->context; grib_context* c = h->context;
long compressed = 0, nsubsets; long compressed = 0, nsubsets;
long i;
grib_iarray* subsets; grib_iarray* subsets;
long* subsets_ar = 0; long* subsets_ar = 0;
long start = 0, radius = 0; long start = 0, radius = 0;
ret = grib_get_long(h, "compressedData", &compressed); int ret = grib_get_long(h, "compressedData", &compressed);
if (ret) if (ret)
return ret; return ret;
if (compressed) { if (compressed) {
@ -168,7 +167,7 @@ static int apply_thinning(grib_accessor* a)
return ret; return ret;
subsets = grib_iarray_new(c, numberOfSubsets / skip + 1, 10); subsets = grib_iarray_new(c, numberOfSubsets / skip + 1, 10);
for (i = 0; i < numberOfSubsets; i += skip + 1) { for (long i = 0; i < numberOfSubsets; i += skip + 1) {
grib_iarray_push(subsets, i + 1); grib_iarray_push(subsets, i + 1);
} }
@ -200,12 +199,11 @@ static int apply_thinning(grib_accessor* a)
static int pack_long(grib_accessor* a, const long* val, size_t* len) static int pack_long(grib_accessor* a, const long* val, size_t* len)
{ {
int err = 0; const grib_accessor_bufr_simple_thinning* self = (grib_accessor_bufr_simple_thinning*)a;
grib_accessor_bufr_simple_thinning* self = (grib_accessor_bufr_simple_thinning*)a;
if (*len == 0) if (*len == 0)
return GRIB_SUCCESS; return GRIB_SUCCESS;
err = apply_thinning(a); int err = apply_thinning(a);
if (err) if (err)
return err; return err;

View File

@ -125,7 +125,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
{ {
int err = 0; int err = 0;
grib_accessor_change_alternative_row_scanning* self = (grib_accessor_change_alternative_row_scanning*)a; grib_accessor_change_alternative_row_scanning* self = (grib_accessor_change_alternative_row_scanning*)a;
grib_context* c = a->context; const grib_context* c = a->context;
grib_handle* h = grib_handle_of_accessor(a); grib_handle* h = grib_handle_of_accessor(a);
long i, j, jr, theEnd, Ni, Nj, k, kp, alternativeRowScanning; long i, j, jr, theEnd, Ni, Nj, k, kp, alternativeRowScanning;
size_t size = 0; size_t size = 0;

View File

@ -146,7 +146,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
size_t size = 0; size_t size = 0;
double* values = NULL; double* values = NULL;
grib_accessor_change_scanning_direction* self = (grib_accessor_change_scanning_direction*)a; grib_accessor_change_scanning_direction* self = (grib_accessor_change_scanning_direction*)a;
grib_context* c = a->context; const grib_context* c = a->context;
grib_handle* h = grib_handle_of_accessor(a); grib_handle* h = grib_handle_of_accessor(a);
const char* cclass_name = a->cclass->name; const char* cclass_name = a->cclass->name;

View File

@ -159,6 +159,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
/* Sets val to the 'index' of the closes date */ /* Sets val to the 'index' of the closes date */
static int unpack_double(grib_accessor* a, double* val, size_t* len) static int unpack_double(grib_accessor* a, double* val, size_t* len)
{ {
const grib_accessor_closest_date* self = (grib_accessor_closest_date*)a;
int err = 0; int err = 0;
long num_forecasts = 0; /* numberOfForecastsUsedInLocalTime */ long num_forecasts = 0; /* numberOfForecastsUsedInLocalTime */
/* These relate to the date and time in Section 1 */ /* These relate to the date and time in Section 1 */
@ -171,9 +173,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
/* These relate to the forecast dates and times in Section 4 */ /* These relate to the forecast dates and times in Section 4 */
long *yearArray, *monthArray, *dayArray, *hourArray, *minuteArray, *secondArray; long *yearArray, *monthArray, *dayArray, *hourArray, *minuteArray, *secondArray;
grib_accessor_closest_date* self = (grib_accessor_closest_date*)a;
grib_handle* h = grib_handle_of_accessor(a); grib_handle* h = grib_handle_of_accessor(a);
grib_context* c = a->context; const grib_context* c = a->context;
*val = -1; /* initialise to an invalid index */ *val = -1; /* initialise to an invalid index */
if ((err = grib_get_long_internal(h, self->numForecasts, &num_forecasts)) != GRIB_SUCCESS) return err; if ((err = grib_get_long_internal(h, self->numForecasts, &num_forecasts)) != GRIB_SUCCESS) return err;

View File

@ -123,7 +123,7 @@ static int test_bit(long a, long b)
static int grib_get_codeflag(grib_accessor* a, long code, char* codename) static int grib_get_codeflag(grib_accessor* a, long code, char* codename)
{ {
grib_accessor_codeflag* self = (grib_accessor_codeflag*)a; const grib_accessor_codeflag* self = (grib_accessor_codeflag*)a;
FILE* f = NULL; FILE* f = NULL;
char fname[1024]; char fname[1024];
char bval[50]; char bval[50];
@ -200,10 +200,10 @@ static int value_count(grib_accessor* a, long* count)
static void dump(grib_accessor* a, grib_dumper* dumper) static void dump(grib_accessor* a, grib_dumper* dumper)
{ {
grib_accessor_codeflag* self = (grib_accessor_codeflag*)a; const grib_accessor_codeflag* self = (grib_accessor_codeflag*)a;
long v; long v = 0;
char flagname[1024]; char flagname[1024] = {0,};
char fname[1024]; char fname[1024] = {0,};
size_t llen = 1; size_t llen = 1;

View File

@ -650,7 +650,7 @@ static int unpack_float(grib_accessor* a, float* val, size_t* len)
static int unpack_double_element(grib_accessor* a, size_t idx, double* val) static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
{ {
// The index idx relates to codedValues NOT values! // The index idx relates to codedValues NOT values!
grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a; const grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a;
grib_handle* hand = grib_handle_of_accessor(a); grib_handle* hand = grib_handle_of_accessor(a);
int err = 0; int err = 0;
size_t size = 0; size_t size = 0;
@ -686,7 +686,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
{ {
grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a; const grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a;
grib_handle* hand = grib_handle_of_accessor(a); grib_handle* hand = grib_handle_of_accessor(a);
size_t size = 0, i = 0; size_t size = 0, i = 0;
double* values = NULL; double* values = NULL;

View File

@ -713,7 +713,7 @@ int grib_accessor_class_expanded_descriptors_set_do_expand(grib_accessor* a, lon
bufr_descriptors_array* grib_accessor_class_expanded_descriptors_get_expanded(grib_accessor* a, int* err) bufr_descriptors_array* grib_accessor_class_expanded_descriptors_get_expanded(grib_accessor* a, int* err)
{ {
grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a; const grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a;
*err = expand(a); *err = expand(a);
return self->expanded; return self->expanded;
} }
@ -722,7 +722,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
{ {
grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a; grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a;
int ret = 0; int ret = 0;
int i; size_t i = 0;
size_t expandedSize; size_t expandedSize;
if (self->rank != 2) { if (self->rank != 2) {
@ -758,7 +758,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a; grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a;
int ret = 0; int ret = 0;
size_t rlen = 0; size_t rlen = 0;
size_t i; size_t i = 0;
ret = expand(a); ret = expand(a);
if (ret) if (ret)