diff --git a/src/grib_accessor_class_long.c b/src/grib_accessor_class_long.c index 8c12b4a18..ef32cb706 100644 --- a/src/grib_accessor_class_long.c +++ b/src/grib_accessor_class_long.c @@ -294,8 +294,7 @@ static int compare(grib_accessor* a, grib_accessor* b) static int pack_string(grib_accessor* a, const char* val, size_t* len) { - char* theEnd = NULL; - long v = 0; + long v = 0; /* The converted value */ #if 0 /* Requires more work e.g. filter */ @@ -304,9 +303,9 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) } #endif - v = strtol(val, &theEnd, 10); - if (theEnd) { - grib_context_log(a->context, GRIB_LOG_ERROR, "trying to pack \"%s\" as long", val); + if (string_to_long(val, &v) != GRIB_SUCCESS) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "Trying to pack \"%s\" as long. String cannot be converted to an integer", val); return GRIB_WRONG_TYPE; } return grib_pack_long(a, &v, len); diff --git a/tests/bufr_set.sh b/tests/bufr_set.sh index 640b4f886..6dd5ea629 100755 --- a/tests/bufr_set.sh +++ b/tests/bufr_set.sh @@ -173,9 +173,16 @@ ${tools_dir}/bufr_set -s ident=' AB CD ' $f $fBufrTmp result=`${tools_dir}/bufr_get -p ident $fBufrTmp` [ "$result" = "AB CD" ] - # ${tools_dir}/bufr_compare $f $fBufrTmp + +#----------------------------------------------------------- +# ECC-1359: string that can be converted to an integer +# ---------------------------------------------------------- +${tools_dir}/bufr_set -s messageLength:s=333 $ECCODES_SAMPLES_PATH/BUFR4_local.tmpl $fBufrTmp +result=`${tools_dir}/bufr_get -p messageLength $fBufrTmp` +[ "$result" = "333" ] + # Clean up rm -f $fLog rm -f $fBufrTmp diff --git a/tests/grib_set.sh b/tests/grib_set.sh index 8f2b7945d..d461fb774 100755 --- a/tests/grib_set.sh +++ b/tests/grib_set.sh @@ -110,5 +110,9 @@ max=`${tools_dir}/grib_get -F%.3f -p max $input` max=`${tools_dir}/grib_get -F%.3f -p max $temp` [ "$max" = "13.097" ] +# ECC-1359: string that can be converted to an integer +# --------------------------------------------------- +${tools_dir}/grib_set -s month:s=6 $ECCODES_SAMPLES_PATH/GRIB2.tmpl $temp +grib_check_key_equals $temp month 6 rm -f $outfile $temp