Re: Using the return value of strlcpy() and strlcat() - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Using the return value of strlcpy() and strlcat()
Date
Msg-id 6698.1552495855@sss.pgh.pa.us
Whole thread Raw
In response to Using the return value of strlcpy() and strlcat()  (ilmari@ilmari.org (Dagfinn Ilmari Mannsåker))
Responses Re: Using the return value of strlcpy() and strlcat()
List pgsql-hackers
ilmari@ilmari.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


pgsql-hackers by date:

Previous
From: Sergei Kornilov
Date:
Subject: Re: using index or check in ALTER TABLE SET NOT NULL
Next
From: Robert Haas
Date:
Subject: Re: hyrax vs. RelationBuildPartitionDesc