From: | Ashwin Agrawal <aagrawal(at)pivotal(dot)io> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Dagfinn Ilmari Mannsåker <ilmari(at)ilmari(dot)org>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Using the return value of strlcpy() and strlcat() |
Date: | 2019-03-14 01:41:52 |
Message-ID: | CALfoeisXr118_wGphaC-tntav9t-nUU_DZ1uKH6cgrJhVQaGRA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Wed, Mar 13, 2019 at 9:51 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> ilmari(at)ilmari(dot)org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=) writes:
> > [ let's convert
> > + strlcpy(buf + buflen, name, NAMEDATALEN);
> > + buflen += strlen(buf + buflen);
> > to
> > + buflen += strlcpy(buf + buflen, name, NAMEDATALEN);
> > ]
>
> 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 ?
From | Date | Subject | |
---|---|---|---|
Next Message | Tsunakawa, Takayuki | 2019-03-14 01:44:57 | RE: Timeout parameters |
Previous Message | Amit Langote | 2019-03-14 01:40:31 | Re: hyrax vs. RelationBuildPartitionDesc |