From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp63.i.mail.ru (smtp63.i.mail.ru [217.69.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id DADFF469710 for ; Tue, 12 May 2020 23:30:46 +0300 (MSK) References: <449685df941ca9a14e102738da413e737e559aea.1589240704.git.v.shpilevoy@tarantool.org> <20200512151324.GA2219@grain> From: Vladislav Shpilevoy Message-ID: <87a91d28-3c4c-a37e-40c0-595faa0ea0d5@tarantool.org> Date: Tue, 12 May 2020 22:30:24 +0200 MIME-Version: 1.0 In-Reply-To: <20200512151324.GA2219@grain> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Tarantool-patches] [PATCH 2/5] decimal: provide MP_DECIMAL extension serializer List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cyrill Gorcunov Cc: tarantool-patches@dev.tarantool.org 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.