Re: Using the return value of strlcpy() and strlcat()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: ilmari(at)ilmari(dot)org (Dagfinn Ilmari Mannsåker )
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Using the return value of strlcpy() and strlcat()
Date: 2019-03-13 16:50:55
Message-ID: 6698.1552495855@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2019-03-13 16:51:05 Re: hyrax vs. RelationBuildPartitionDesc
Previous Message Sergei Kornilov 2019-03-13 16:46:50 Re: using index or check in ALTER TABLE SET NOT NULL