Re: Replace remaining StrNCpy() by strlcpy() - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Replace remaining StrNCpy() by strlcpy()
Date
Msg-id 2268534.1596456766@sss.pgh.pa.us
Whole thread Raw
In response to Re: Replace remaining StrNCpy() by strlcpy()  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Replace remaining StrNCpy() by strlcpy()  (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>)
Re: Replace remaining StrNCpy() by strlcpy()  (David Rowley <dgrowleyml@gmail.com>)
List pgsql-hackers
I wrote:
> David Rowley <dgrowleyml@gmail.com> writes:
>> Will mean that we'll now no longer zero the full length of the m_xlog
>> field after the end of the string. Won't that mean we'll start writing
>> junk bytes to the stats collector?

> StrNCpy doesn't zero-fill the destination today either (except for
> the very last byte).

Oh, no, I take that back --- didn't read all of the strncpy man
page :-(.  Yeah, this is a point.  We'd need to check each call
site to see whether the zero-padding matters.

In the specific case of the stats collector, if you don't want
to be sending junk bytes then you'd better be memset'ing the
whole message buffer not just this string field.  So I'm not
sure that the argument has any force there.  But in places
like namecpy() and namestrcpy() we absolutely do mean to be
zeroing the whole destination buffer.

memset plus strlcpy might still be preferable to StrNCpy for
readability by people new to Postgres; but it's less of a
slam dunk than I thought.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Magnus Hagander
Date:
Subject: Re: [PATCH] Add section headings to index types doc
Next
From: Tom Lane
Date:
Subject: Re: [PATCH] Add section headings to index types doc