From: | ilmari(at)ilmari(dot)org (Dagfinn Ilmari Mannsåker ) |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Ashwin Agrawal <aagrawal(at)pivotal(dot)io>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Using the return value of strlcpy() and strlcat() |
Date: | 2019-03-14 11:10:58 |
Message-ID: | d8jd0mt6799.fsf@dalvik.ping.uio.no |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
> Ashwin Agrawal <aagrawal(at)pivotal(dot)io> writes:
>> On Wed, Mar 13, 2019 at 9:51 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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.
Yeah, Andrew Gierth pointed this out on IRC as well.
>>> 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.
Please consider this patch withdrawn.
- ilmari
--
"I use RMS as a guide in the same way that a boat captain would use
a lighthouse. It's good to know where it is, but you generally
don't want to find yourself in the same spot." - Tollef Fog Heen
From | Date | Subject | |
---|---|---|---|
Next Message | David Rowley | 2019-03-14 11:21:29 | Re: Removing unneeded self joins |
Previous Message | Auguste Comte | 2019-03-14 11:10:17 | Google Summer of Code |