mirror of https://github.com/ecmwf/eccodes.git
Check for failures in unpack_string
This commit is contained in:
parent
cf3ea9b924
commit
c19b933b0f
|
@ -13,7 +13,7 @@ program grib_dump_test
|
||||||
integer :: ifile, iret, msgid
|
integer :: ifile, iret, msgid
|
||||||
integer :: product_kind
|
integer :: product_kind
|
||||||
character(len=10) :: product_string
|
character(len=10) :: product_string
|
||||||
character(len=100) :: infile_name
|
character(len=512) :: infile_name
|
||||||
|
|
||||||
call getarg(1, product_string)
|
call getarg(1, product_string)
|
||||||
product_kind = CODES_PRODUCT_GRIB
|
product_kind = CODES_PRODUCT_GRIB
|
||||||
|
|
|
@ -9,5 +9,6 @@
|
||||||
|
|
||||||
. ./include.ctest.sh
|
. ./include.ctest.sh
|
||||||
|
|
||||||
${examples_dir}/eccodes_f_codes_dump grib ${data_dir}/sample.grib2
|
cd $data_dir
|
||||||
${examples_dir}/eccodes_f_codes_dump bufr ${data_dir}/bufr/airs_57.bufr
|
${examples_dir}/eccodes_f_codes_dump grib sample.grib2
|
||||||
|
${examples_dir}/eccodes_f_codes_dump bufr bufr/airs_57.bufr
|
||||||
|
|
|
@ -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)
|
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) {
|
if (a->cclass->unpack_double && a->cclass->unpack_double != &unpack_double) {
|
||||||
double val = 0.0;
|
double val = 0.0;
|
||||||
size_t l = 1;
|
size_t l = 1;
|
||||||
grib_unpack_double(a, &val, &l); // TODO(masn): check return value
|
err = grib_unpack_double(a, &val, &l);
|
||||||
//if (err) return err;
|
if (err) return err;
|
||||||
snprintf(v, 64, "%g", val);
|
snprintf(v, 64, "%g", val);
|
||||||
*len = strlen(v);
|
*len = strlen(v);
|
||||||
grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting double %s to string", a->name);
|
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) {
|
if (a->cclass->unpack_long && a->cclass->unpack_long != &unpack_long) {
|
||||||
long val = 0;
|
long val = 0;
|
||||||
size_t l = 1;
|
size_t l = 1;
|
||||||
grib_unpack_long(a, &val, &l); // TODO(masn): check return value
|
err = grib_unpack_long(a, &val, &l);
|
||||||
//if (err) return err;
|
if (err) return err;
|
||||||
snprintf(v, 64, "%ld", val);
|
snprintf(v, 64, "%ld", val);
|
||||||
*len = strlen(v);
|
*len = strlen(v);
|
||||||
grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting long %s to string\n", a->name);
|
grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting long %s to string\n", a->name);
|
||||||
|
|
Loading…
Reference in New Issue