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

From: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
To: Dagfinn Ilmari Mannsåker <ilmari(at)ilmari(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, 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:45:22
Message-ID: CAKJS1f8FjLCD17EOKXcday9D4orxwhzkM22mzPVhm63jWkve-Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, 15 Mar 2019 at 00:11, Dagfinn Ilmari Mannsåker
<ilmari(at)ilmari(dot)org> wrote:
> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
> > 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.

Amusingly it seems the strlcpy() return value of the chars it would
have copied if it didn't run out of space is not all that useful for
us. I see exactly 2 matches of git grep "= strlcpy". The
isolation_init() one looks genuine, but the SerializeLibraryState()
looks a bit bogus. Looking at EstimateLibraryStateSpace() it seems it
estimates the exact space, so the strlcpy should never cut short, but
it does seem like a bad example to leave laying around.

We should have maybe thought a bit harder when we put that strlcpy
code into the codebase and considered if we might have been better off
inventing our own function that just returns what it did copy instead
of what it would have.

--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kyotaro HORIGUCHI 2019-03-14 11:50:16 Re: [HACKERS] PATCH: multivariate histograms and MCV lists
Previous Message David Rowley 2019-03-14 11:21:29 Re: Removing unneeded self joins