Compiler warnings: comparison of integers of different signs [-Wsign-compare]

This commit is contained in:
Shahram Najm 2023-03-04 12:44:37 +00:00
parent d1d094cf8a
commit f48f536a1d
3 changed files with 18 additions and 15 deletions

View File

@ -167,17 +167,18 @@ static int get_native_type(grib_accessor* a)
static int unpack_string(grib_accessor* a, char* val, size_t* len)
{
int i = 0;
size_t i = 0;
grib_handle* hand = grib_handle_of_accessor(a);
const size_t alen = a->length;
if (len[0] < (a->length + 1)) {
grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s it contains %ld values",
if (len[0] < (alen + 1)) {
grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%zu) for %s, it contains %ld values",
len[0], a->name, a->length + 1);
len[0] = 0;
return GRIB_ARRAY_TOO_SMALL;
}
for (i = 0; i < a->length; i++)
for (i = 0; i < alen; i++)
val[i] = hand->buffer->data[a->offset + i];
val[i] = 0;
len[0] = i;
@ -186,16 +187,17 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len)
static int pack_string(grib_accessor* a, const char* val, size_t* len)
{
int i = 0;
size_t i = 0;
grib_handle* hand = grib_handle_of_accessor(a);
if (len[0] > (a->length) + 1) {
const size_t alen = a->length;
if (len[0] > (alen + 1)) {
grib_context_log(a->context, GRIB_LOG_ERROR,
"pack_string: Wrong size (%lu) for %s it contains %ld values", len[0], a->name, a->length + 1);
"pack_string: Wrong size (%zu) for %s, it contains %ld values", len[0], a->name, a->length + 1);
len[0] = 0;
return GRIB_BUFFER_TOO_SMALL;
}
for (i = 0; i < a->length; i++) {
for (i = 0; i < alen; i++) {
if (i < len[0])
hand->buffer->data[a->offset + i] = val[i];
else

View File

@ -187,8 +187,8 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
if ((err = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS)
return err;
if (size > Ni * Nj) {
grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: wrong values size!=Ni*Nj (%ld!=%ld*%ld)", size, Ni, Nj);
if ( size > (size_t)(Ni * Nj) ) {
grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: wrong values size!=Ni*Nj (%zu!=%ld*%ld)", size, Ni, Nj);
return GRIB_WRONG_ARRAY_SIZE;
}

View File

@ -219,8 +219,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a;
grib_handle* hand = grib_handle_of_accessor(a);
int err = GRIB_SUCCESS, i = 0;
size_t buflen = 0;
int err = GRIB_SUCCESS;
size_t buflen = 0, i = 0;
struct aec_stream strm;
double bscale = 0;
double dscale = 0;
@ -334,8 +334,9 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a;
grib_handle* hand = grib_handle_of_accessor(a);
int err = GRIB_SUCCESS, i = 0, is_constant_field = 0;
size_t buflen = 0;
int err = GRIB_SUCCESS;
size_t buflen = 0, i = 0;
bool is_constant_field = false;
unsigned char* buf = NULL;
unsigned char* encoded = NULL;
@ -395,7 +396,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
}
if (min == max) {
is_constant_field = 1;
is_constant_field = true;
} else {
if (bits_per_value == 0) {
/* ECC-1202: A non-constant field with bitsPerValue==0! */