ECC-1283: bufr_compare: Does not detect differences in string arrays

This commit is contained in:
Shahram Najm 2021-10-02 17:38:22 +01:00
parent 139d9bc1dc
commit 433bd328ad
1 changed files with 30 additions and 11 deletions

View File

@ -664,6 +664,29 @@ static char* get_keyname_without_rank(const char* name)
return ret;
}
static int are_strings_both_missing(grib_handle* h1, grib_handle* h2, const char* key,
const char* s1, const char* s2,
size_t slen1, size_t slen2)
{
/* Note: one string could have all its bits=1 and the other empty */
int is_miss_1 = 0, is_miss_2 = 0;
if (strlen(s1) == 0) {
is_miss_1 = 1;
} else {
grib_accessor* a1 = grib_find_accessor(h1, key);
is_miss_1 = grib_is_missing_string(a1, (unsigned char*)s1, slen1);
}
if (strlen(s2) == 0) {
is_miss_2 = 1;
} else {
grib_accessor* a2 = grib_find_accessor(h2, key);
is_miss_2 = grib_is_missing_string(a2, (unsigned char*)s2, slen2);
}
if (is_miss_1 && is_miss_2) {
return 1; /* both classed as missing */
}
return 0;
}
static int compare_values(grib_runtime_options* options, grib_handle* handle1, grib_handle* handle2, const char* name, int type)
{
size_t len1 = 0;
@ -818,17 +841,10 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
}
if (err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS) {
if (grib_inline_strcmp(sval1, sval2) != 0) {
/* Check if strings are 'missing'.
/* Strings are different. Now check if strings are 'missing'.
* Note: one string could have all its bits=1 and the other empty */
int equal = 0;
grib_accessor* a1 = grib_find_accessor(handle1, name);
grib_accessor* a2 = grib_find_accessor(handle2, name);
int is_miss_1 = grib_is_missing_string(a1, (unsigned char*)sval1, slen1);
int is_miss_2 = grib_is_missing_string(a2, (unsigned char*)sval2, slen2);
if (is_miss_1 && is_miss_2) {
equal = 1;
}
if (!equal) {
int both_missing = are_strings_both_missing(handle1, handle2, name, sval1, sval2,slen1, slen2);
if (!both_missing) {
printInfo(handle1);
printf("string [%s]: [%s] != [%s]\n", name, sval1, sval2);
err1 = GRIB_VALUE_MISMATCH;
@ -869,7 +885,10 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
countdiff = 0;
for (ii = 0; ii < len1; ii++) {
if (grib_inline_strcmp(svals1[ii], svals2[ii]) != 0) {
countdiff++;
/* Strings are different. Now check if strings are 'missing' */
int both_missing = are_strings_both_missing(handle1, handle2, name, svals1[ii], svals2[ii],len1, len2);
if (!both_missing)
countdiff++;
}
}
if (countdiff) {