From e4edb7b81d4620faeacc9db3f023e45c4e13ed10 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 25 Feb 2021 21:17:24 +0000 Subject: [PATCH] ECC-1207: GRIB2: BiFourier packing error --- ..._accessor_class_data_g2bifourier_packing.c | 19 +++++++++++-------- tests/grib_lam_bf.c | 5 +---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/grib_accessor_class_data_g2bifourier_packing.c b/src/grib_accessor_class_data_g2bifourier_packing.c index 07a6d3770..df000c453 100644 --- a/src/grib_accessor_class_data_g2bifourier_packing.c +++ b/src/grib_accessor_class_data_g2bifourier_packing.c @@ -411,19 +411,22 @@ static double laplam(bif_trunc_t* bt, const double val[]) } lmax = l; - if (lmax == 0) - return 0.; + if (lmax == 0) { /* ECC-1207 */ + free(itab1); + free(itab2); + return 0.; + } + if (lmax < 0) { + free(itab1); + free(itab2); + Assert(!"data_g2bifourier_packing::laplam: lmax must be >= 0"); + return 0; + } /* * Now, itab2 contains all possible values of i*i+j*j, and itab1 contains * the rank of all i*i+j*j */ - if (lmax <= 0) { - free(itab1); - free(itab2); - Assert(!"data_g2bifourier_packing::laplam: lmax must be > 0"); - return 0; - } znorm = (double*)calloc(lmax, sizeof(double)); zw = (double*)malloc(sizeof(double) * lmax); diff --git a/tests/grib_lam_bf.c b/tests/grib_lam_bf.c index 8b302fb95..81b9ec137 100644 --- a/tests/grib_lam_bf.c +++ b/tests/grib_lam_bf.c @@ -700,7 +700,7 @@ int main(int argc, char* argv[]) trunc[1].trunc = 77; trunc[1].subtrunc = 77; trunc[1].subnsmax = NSTRON; - trunc[2].subnmsmax = NSTRON; + trunc[1].subnmsmax = NSTRON; trunc[1].len = 4 * (NSMAX + 1) * (NMSMAX + 1); trunc[1].values = (double*)malloc(sizeof(double) * trunc[1].len); trunc[1].name = "rectangle_rectangle"; @@ -715,8 +715,6 @@ int main(int argc, char* argv[]) trunc[2].values = (double*)values; trunc[2].name = "ellipse_full"; - - for (itrunc = 0; itrunc < 3; itrunc++) { for (igrid = 0; igrid < 3; igrid++) { GRIB_CHECK(((h = grib_handle_new_from_samples(NULL, "lambert_bf_grib2")) == NULL), 0); @@ -804,7 +802,6 @@ int main(int argc, char* argv[]) long int nsmax, nmsmax; char geometry[128]; - sprintf(f, "lam_bf_%s_%s.grib", grids[igrid], trunc[itrunc].name); fp = fopen(f, "rb"); h = grib_handle_new_from_file(0, fp, &err);