ECC-1359: codes_set_string: Fails for integer key even if string can be converted to an integer

This commit is contained in:
Shahram Najm 2022-03-02 17:43:41 +00:00
parent cc09ad375d
commit 55a95d17bd
3 changed files with 16 additions and 6 deletions

View File

@ -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);

View File

@ -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

View File

@ -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