ECC-1410: GRIB: C API: keys iterator name is NULL

This commit is contained in:
Shahram Najm 2022-06-17 18:58:21 +01:00
parent d29e94822f
commit c72f1b7497
4 changed files with 69 additions and 0 deletions

View File

@ -151,6 +151,10 @@ static int skip(grib_keys_iterator* kiter)
mark_seen(kiter, kiter->current->name);
}
/* ECC-1410 */
if (kiter->current->all_names[0] == NULL)
return 1;
return 0;
}

View File

@ -20,6 +20,7 @@ list(APPEND test_bins
grib_read_index
unit_tests
bufr_keys_iter
grib_keys_iter
gauss_sub
grib_nearest_test
grib_util_set_spec
@ -154,6 +155,7 @@ if( HAVE_BUILD_TOOLS )
bufr_ls_json
bufr_change_edition
bufr_keys_iter
grib_keys_iter
bufr_get_element
bufr_wmo_tables
bufr_extract_headers

37
tests/grib_keys_iter.c Normal file
View File

@ -0,0 +1,37 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include "eccodes.h"
int main(int argc, char* argv[])
{
FILE* f = NULL;
codes_handle* h = NULL;
int err = 0;
assert(argc == 2);
f = fopen(argv[1], "rb");
assert(f);
while ((h = codes_handle_new_from_file(0, f, PRODUCT_GRIB, &err)) != NULL) {
codes_keys_iterator* kiter = NULL;
/* Use namespace of NULL to get ALL keys */
kiter = codes_keys_iterator_new(h, 0, /*namespace=*/NULL);
assert(kiter);
while (codes_keys_iterator_next(kiter)) {
const char* name = codes_keys_iterator_get_name(kiter);
assert(name);
printf("%s\n", name);
}
codes_keys_iterator_delete(kiter);
codes_handle_delete(h);
}
fclose(f);
return 0;
}

26
tests/grib_keys_iter.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/sh
# (C) Copyright 2005- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
#
. ./include.ctest.sh
label="grib_keys_iter_test"
tempOut=temp.$label.out
cd ${data_dir}
# ECC-1410
f='tigge/tiggelam_cnmc_sfc.grib'
$EXEC ${test_dir}/grib_keys_iter $f
for f in *grib *grib[12] tigge/*grib; do
$EXEC ${test_dir}/grib_keys_iter $f > $tempOut
done
rm -f $tempOut