[Tarantool-patches] [PATCH 2/5] decimal: provide MP_DECIMAL extension serializer

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Tue May 12 23:30:24 MSK 2020


Hi! Thanks for the review!

On 12/05/2020 17:13, Cyrill Gorcunov wrote:
> On Tue, May 12, 2020 at 01:45:49AM +0200, Vladislav Shpilevoy wrote:
>> +
>> +int
>> +mp_snprint_decimal(char *buf, int size, const char **data, uint32_t len)
>> +{
>> +	decimal_t d;
>> +	if (decimal_unpack(data, len, &d) == NULL)
>> +		return -1;
>> +	return snprintf(buf, size, "%s", decimal_to_string(&d));
>> +}
> 
> This looks suspicious -- if buffer size is not enough the snprintf
> returns not the number of bytes really written but rather a number
> of bytes needed to write the desired string. Are you sure it is
> safe to return snprintf result here?

Yes, I am sure it is safe and correct. mp_snprint() returns exactly this -
an snprintf-like result. So all printers, used inside of it, should do the
same. At least this is what is documented and covered by existing tests.


More information about the Tarantool-patches mailing list