ECCC-MSC / libecbufr

libecbufr is a general purpose, template-oriented BUFR encoding/decoding library
Other
10 stars 7 forks source link

bufr_descriptor_set_svalue() doesn't work on "fresh" descriptors #9

Open vsouvan opened 4 years ago

vsouvan commented 4 years ago

Sample code:

BufrDescriptor* d = bufr_create_descriptor( tables, desc ); bufr_descriptor_set_svalue(d, value); fprintf(stderr,"set string to '%s' ('%s')\n", bufr_descriptor_get_svalue(d, &l),value);

The output ends up being an empty string rather than what we're assigning.

the root of the problem is that bufr_create_descriptor() does a lookup in the table and sets d->encoding.type, but that's all it sets in the encoding section. Well, bufr_descriptor_set_svalue() comes along and falls down to:

bufr_value_set_string( cb->value, sval, cb->encoding.nbits/8 );

which, obviously, is going to fail miserably since cb->encoding.nbits==0.

Proper fix is to ensure that bufr_create_descriptor() fully defines the encoding based on the table entry.


Imported from Launchpad using lp2gh.