Re: Using the return value of strlcpy() and strlcat()
| От | Tom Lane |
|---|---|
| Тема | Re: Using the return value of strlcpy() and strlcat() |
| Дата | |
| Msg-id | 32001.1552528633@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | Re: Using the return value of strlcpy() and strlcat() (Ashwin Agrawal <aagrawal@pivotal.io>) |
| Ответы |
Re: Using the return value of strlcpy() and strlcat()
|
| Список | pgsql-hackers |
Ashwin Agrawal <aagrawal@pivotal.io> writes:
> On Wed, Mar 13, 2019 at 9:51 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> I don't think that's a safe transformation: what strlcpy returns is
>> strlen(src), which might be different from what it was actually
>> able to fit into the destination.
>> Sure, they're equivalent if no truncation occurred; but if we were
>> 100.00% sure of no truncation, we'd likely not bother with strlcpy.
> So, if return value < length (3rd argument) we should be able to use the
> return value and avoid the strlen, else do the strlen ?
Mmm ... if there's a way to do it that's not messy and typo-prone,
maybe. But I'm dubious that the potential gain is worth complicating
the code. The strings involved aren't usually all that long.
regards, tom lane
В списке pgsql-hackers по дате отправления: