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

From Tom Lane
Subject Re: Replace remaining StrNCpy() by strlcpy()
Date
Msg-id 2267028.1596454733@sss.pgh.pa.us
Whole thread Raw
In response to Re: Replace remaining StrNCpy() by strlcpy()  (David Rowley <dgrowleyml@gmail.com>)
Responses Re: Replace remaining StrNCpy() by strlcpy()
List pgsql-hackers
David Rowley <dgrowleyml@gmail.com> writes:
> - StrNCpy(msg.m_xlog, xlog, sizeof(msg.m_xlog));
> + strlcpy(msg.m_xlog, xlog, sizeof(msg.m_xlog));

> 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).  If you need that, you need to memset the
dest buffer ahead of time.

I didn't review the patch in complete detail, but the principle
seems sound to me, and strlcpy is surely more standard than StrNCpy.

            regards, tom lane



pgsql-hackers by date:

Previous
From: ilmari@ilmari.org (Dagfinn Ilmari Mannsåker)
Date:
Subject: Re: [PATCH] Add section headings to index types doc
Next
From: Amit Langote
Date:
Subject: Re: [POC] Fast COPY FROM command for the table with foreign partitions