From adc0450516d3154e7e4825bb6a7371bc7507c1b6 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 2 Feb 2023 19:49:48 +0000 Subject: [PATCH] ECC-1522: prgenv/amd: Test eccodes_t_grib_bpv_limit fails --- src/grib_scaling.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/grib_scaling.cc b/src/grib_scaling.cc index d5dc80719..d7654889f 100644 --- a/src/grib_scaling.cc +++ b/src/grib_scaling.cc @@ -40,16 +40,17 @@ long grib_get_binary_scale_fact(double max, double min, long bpval, int* ret) long scale = 0; const long last = 127; /* Depends on edition, should be parameter */ unsigned long maxint = 0; + const size_t ulong_size = sizeof(maxint) * 8; /* See ECC-246 unsigned long maxint = grib_power(bpval,2) - 1; double dmaxint=(double)maxint; */ - const double dmaxint = grib_power(bpval, 2) - 1; - if (dmaxint >= ULONG_MAX) { + if (bpval >= ulong_size) { *ret = GRIB_OUT_OF_RANGE; /*overflow*/ return 0; } + const double dmaxint = grib_power(bpval, 2) - 1; maxint = (unsigned long)dmaxint; /* Now it's safe to cast */ *ret = 0;