[Tarantool-patches] [PATCH v4 1/4] util: introduce strlcpy helper

Serge Petrenko sergepetrenko at tarantool.org
Fri Dec 11 14:07:53 MSK 2020


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



More information about the Tarantool-patches mailing list