Check for failures in unpack_string

This commit is contained in:
Shahram Najm 2023-08-22 17:02:48 +01:00
parent cf3ea9b924
commit c19b933b0f
3 changed files with 9 additions and 8 deletions

View File

@ -13,7 +13,7 @@ program grib_dump_test
integer :: ifile, iret, msgid
integer :: product_kind
character(len=10) :: product_string
character(len=100) :: infile_name
character(len=512) :: infile_name
call getarg(1, product_string)
product_kind = CODES_PRODUCT_GRIB

View File

@ -9,5 +9,6 @@
. ./include.ctest.sh
${examples_dir}/eccodes_f_codes_dump grib ${data_dir}/sample.grib2
${examples_dir}/eccodes_f_codes_dump bufr ${data_dir}/bufr/airs_57.bufr
cd $data_dir
${examples_dir}/eccodes_f_codes_dump grib sample.grib2
${examples_dir}/eccodes_f_codes_dump bufr bufr/airs_57.bufr

View File

@ -356,12 +356,12 @@ static int unpack_float(grib_accessor* a, float* v, size_t* len)
static int unpack_string(grib_accessor* a, char* v, size_t* len)
{
//int err = 0;
int err = 0;
if (a->cclass->unpack_double && a->cclass->unpack_double != &unpack_double) {
double val = 0.0;
size_t l = 1;
grib_unpack_double(a, &val, &l); // TODO(masn): check return value
//if (err) return err;
err = grib_unpack_double(a, &val, &l);
if (err) return err;
snprintf(v, 64, "%g", val);
*len = strlen(v);
grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting double %s to string", a->name);
@ -371,8 +371,8 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
if (a->cclass->unpack_long && a->cclass->unpack_long != &unpack_long) {
long val = 0;
size_t l = 1;
grib_unpack_long(a, &val, &l); // TODO(masn): check return value
//if (err) return err;
err = grib_unpack_long(a, &val, &l);
if (err) return err;
snprintf(v, 64, "%ld", val);
*len = strlen(v);
grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting long %s to string\n", a->name);