From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp16.mail.ru (smtp16.mail.ru [94.100.176.153]) (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 713DA45C304 for ; Fri, 11 Dec 2020 14:07:55 +0300 (MSK) References: <20201210161832.729439-1-gorcunov@gmail.com> <20201210161832.729439-2-gorcunov@gmail.com> <02c6bfc0-ceb1-c1bc-5d8b-2450dbc082bc@tarantool.org> <20201211100408.GC544004@grain> From: Serge Petrenko Message-ID: Date: Fri, 11 Dec 2020 14:07:53 +0300 MIME-Version: 1.0 In-Reply-To: <20201211100408.GC544004@grain> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [Tarantool-patches] [PATCH v4 1/4] util: introduce strlcpy helper List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cyrill Gorcunov Cc: Mons Anderson , tml , Vladislav Shpilevoy 11.12.2020 13:04, Cyrill Gorcunov пишет: > On Fri, Dec 11, 2020 at 10:58:21AM +0300, Serge Petrenko wrote: >>>> +size_t >>>> +strlcpy(char *dst, const char *src, size_t size) >>>> +{ >>>> +    size_t src_len = strlen(src); >>>> +    if (size) { >> >> One nit: we usually use `if(smth)` for boolean values only. >> >> For integer values please use the explicit variant: `if(size != 0)` > Ouch, indeed. I'll force push an update once Vlad comment out > the series. > > n.b. You know every time I see `if (x != [0|NULL])` statement > it driving me nuts: the language standart is pretty clear for > `if ()` statement and explains how it is evaluated and I always > wonder who exactly invented this explisit test for non-zero/nil?! > Now *every* if statement requires 5 additional symbols for simply > nothing :( I suspect the person who started to use this form > simply was not aware of the language standart. I guess it's more about code readability rather than producing a correct expression according to the standard. I was also surprised by this rule at first, but got used to it now. It's all about what you're used to, after all. > > Surely I try to follow current code style, just saying :) -- Serge Petrenko