Merge branch 'develop' into feature/marsLevtype

This commit is contained in:
Shahram Najm 2021-07-28 15:24:45 +01:00
commit f12111b0df
4 changed files with 26 additions and 8 deletions

View File

@ -667,7 +667,7 @@ static grib_darray* decode_double_array(grib_context* c, unsigned char* data, lo
}
for (j = 0; j < self->numberOfSubsets; j++) {
lval = grib_decode_size_t(data, pos, localWidth);
if (grib_is_all_bits_one(lval, localWidth) && canBeMissing) {
if (canBeMissing && grib_is_all_bits_one(lval, localWidth)) {
dval = GRIB_MISSING_DOUBLE;
}
else {
@ -678,7 +678,7 @@ static grib_darray* decode_double_array(grib_context* c, unsigned char* data, lo
}
else {
/* ECC-428 */
if (grib_is_all_bits_one(lval, modifiedWidth) && canBeMissing) {
if (canBeMissing && grib_is_all_bits_one(lval, modifiedWidth)) {
dval = GRIB_MISSING_DOUBLE;
}
else {
@ -1096,7 +1096,7 @@ static double decode_double_value(grib_context* c, unsigned char* data, long* po
}
lval = grib_decode_size_t(data, pos, modifiedWidth);
if (grib_is_all_bits_one(lval, modifiedWidth) && canBeMissing) {
if (canBeMissing && grib_is_all_bits_one(lval, modifiedWidth)) {
dval = GRIB_MISSING_DOUBLE;
}
else {

View File

@ -93,7 +93,7 @@ static bufr_descriptors_array* grib_bufr_descriptors_array_resize_to(bufr_descri
static bufr_descriptors_array* grib_bufr_descriptors_array_resize(bufr_descriptors_array* v)
{
const int newsize = v->incsize + v->size;
const size_t newsize = v->incsize + v->size;
return grib_bufr_descriptors_array_resize_to(v, newsize);
}

View File

@ -126,7 +126,7 @@ static grib_iarray* grib_iarray_resize_to(grib_iarray* v, size_t newsize)
static grib_iarray* grib_iarray_resize(grib_iarray* v)
{
const int newsize = v->incsize + v->size;
const size_t newsize = v->incsize + v->size;
return grib_iarray_resize_to(v, newsize);
}

View File

@ -10,6 +10,8 @@
#include "grib_api_internal.h"
static const char* ENV_VAR = "ECCODES_GRIB_REPAIR_MAX_NUM_MESSAGES";
static void usage(const char* name)
{
fprintf(stderr, "Usage: %s in out [bad]\n", name);
@ -25,8 +27,10 @@ int main(int argc, char** argv)
char *cout, *cbad;
size_t data_len = SIZE;
long count = 0;
unsigned long count = 0;
unsigned long MAX_NUM_MESSAGES = 100*1000;
unsigned char* data;
char* sMaxNumMessages = NULL;
if (argc != 3 && argc != 4)
usage(argv[0]);
@ -56,14 +60,28 @@ int main(int argc, char** argv)
bad = out;
cbad = cout;
}
sMaxNumMessages = getenv(ENV_VAR);
if (sMaxNumMessages) {
long lmax = 0;
if (string_to_long(sMaxNumMessages, &lmax) == GRIB_SUCCESS) {
MAX_NUM_MESSAGES = lmax;
}
}
for (;;) {
size_t len = SIZE;
long ret = wmo_read_grib_from_file(in, buffer, &len);
if (ret == GRIB_END_OF_FILE && len == 0)
break;
if (count > MAX_NUM_MESSAGES) {
/* ECC-1265 */
printf("\nExceeded the maximum number of messages. Limit = %lu.\n", MAX_NUM_MESSAGES);
printf("This limit can be overridden by setting the environment variable %s.\n", ENV_VAR);
break;
}
printf("GRIB %ld: size: %ld code: %ld (%s)\n", ++count, (long)len, ret, grib_get_error_message(ret));
printf("GRIB %lu: size: %ld code: %ld (%s)\n", ++count, (long)len, ret, grib_get_error_message(ret));
switch (ret) {
case 0:
@ -80,7 +98,7 @@ int main(int argc, char** argv)
len = data_len = SIZE;
data = (unsigned char*)&buffer[0];
ret = grib_read_any_from_memory(NULL, &data, &data_len, buffer, &len);
printf(" -> GRIB %ld: size: %ld code: %ld (%s)\n", count, (long)len, ret, grib_get_error_message(ret));
printf(" -> GRIB %lu: size: %ld code: %ld (%s)\n", count, (long)len, ret, grib_get_error_message(ret));
if (ret == 0) {
if (fwrite(buffer, 1, len, bad) != len) {
perror(cbad);