mirror of https://github.com/ecmwf/eccodes.git
ECC-1631: Segmentation fault: Decode bufrdcExpandedDescriptors as string
This commit is contained in:
parent
9838b3b21b
commit
0d14b54d80
|
@ -142,15 +142,14 @@ static grib_accessor* get_accessor(grib_accessor* a)
|
||||||
static int unpack_long(grib_accessor* a, long* val, size_t* len)
|
static int unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||||
{
|
{
|
||||||
grib_accessor* descriptors = 0;
|
grib_accessor* descriptors = 0;
|
||||||
size_t rlen = 0, l;
|
size_t rlen = 0, l;
|
||||||
long lenall = 0;
|
long lenall = 0;
|
||||||
size_t i;
|
size_t i = 0;
|
||||||
long* v = 0;
|
long* v = 0;
|
||||||
grib_context* c = a->context;
|
grib_context* c = a->context;
|
||||||
|
|
||||||
descriptors = get_accessor(a);
|
descriptors = get_accessor(a);
|
||||||
if (!descriptors)
|
if (!descriptors) return GRIB_NOT_FOUND;
|
||||||
return GRIB_NOT_FOUND;
|
|
||||||
|
|
||||||
grib_value_count(a, &lenall);
|
grib_value_count(a, &lenall);
|
||||||
v = (long*)grib_context_malloc_clear(c, sizeof(long) * lenall);
|
v = (long*)grib_context_malloc_clear(c, sizeof(long) * lenall);
|
||||||
|
@ -171,29 +170,30 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||||
static int unpack_string_array(grib_accessor* a, char** buffer, size_t* len)
|
static int unpack_string_array(grib_accessor* a, char** buffer, size_t* len)
|
||||||
{
|
{
|
||||||
grib_accessor* descriptors = 0;
|
grib_accessor* descriptors = 0;
|
||||||
grib_context* c = a->context;
|
size_t l = 0;
|
||||||
long l = 0;
|
long lenall = 0;
|
||||||
size_t size, i;
|
size_t i = 0;
|
||||||
|
long* v = 0;
|
||||||
char buf[25] = {0,};
|
char buf[25] = {0,};
|
||||||
long* v = 0;
|
grib_context* c = a->context;
|
||||||
|
|
||||||
descriptors = get_accessor(a);
|
descriptors = get_accessor(a);
|
||||||
if (!descriptors)
|
if (!descriptors) return GRIB_NOT_FOUND;
|
||||||
return GRIB_NOT_FOUND;
|
|
||||||
|
|
||||||
value_count(descriptors, &l);
|
grib_value_count(a, &lenall);
|
||||||
|
l = lenall;
|
||||||
if (l > *len)
|
if (l > *len)
|
||||||
return GRIB_ARRAY_TOO_SMALL;
|
return GRIB_ARRAY_TOO_SMALL;
|
||||||
|
|
||||||
v = (long*)grib_context_malloc_clear(c, sizeof(long) * l);
|
v = (long*)grib_context_malloc_clear(c, sizeof(long) * l);
|
||||||
size = l;
|
grib_unpack_long(descriptors, v, &l);
|
||||||
unpack_long(a, v, &size);
|
|
||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < l; i++) {
|
||||||
snprintf(buf, sizeof(buf), "%06ld", v[i]);
|
snprintf(buf, sizeof(buf), "%06ld", v[i]);
|
||||||
buffer[i] = grib_context_strdup(c, buf);
|
buffer[i] = grib_context_strdup(c, buf);
|
||||||
}
|
}
|
||||||
*len = l;
|
*len = l;
|
||||||
|
grib_context_free(c,v);
|
||||||
|
|
||||||
return GRIB_SUCCESS;
|
return GRIB_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,4 +35,9 @@ do
|
||||||
rm -f $res_desc $diff_desc
|
rm -f $res_desc $diff_desc
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# ECC-1631: Segmentation fault: Decode bufrdcExpandedDescriptors as string
|
||||||
|
echo 'print "[bufrdcExpandedDescriptors:s]";' | ${tools_dir}/codes_bufr_filter - $ECCODES_SAMPLES_PATH/BUFR4.tmpl
|
||||||
|
|
||||||
|
|
||||||
|
# Clean up
|
||||||
rm -f bufrdc_desc_ref.filter
|
rm -f bufrdc_desc_ref.filter
|
||||||
|
|
Loading…
Reference in New Issue