Re: Replace remaining StrNCpy() by strlcpy()

Поиск
Список
Период
Сортировка
Искать
От
Tom Lane
Тема
Re: Replace remaining StrNCpy() by strlcpy()
Дата
Msg-id
2268534.1596456766@sss.pgh.pa.us
Ответ на
Список
Дерево обсуждения
Replace remaining StrNCpy() by strlcpy() Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Re: Replace remaining StrNCpy() by strlcpy() David Rowley <dgrowleyml@gmail.com>
Re: Replace remaining StrNCpy() by strlcpy() Tom Lane <tgl@sss.pgh.pa.us>
Re: Replace remaining StrNCpy() by strlcpy() Tom Lane <tgl@sss.pgh.pa.us>
Re: Replace remaining StrNCpy() by strlcpy() Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Re: Replace remaining StrNCpy() by strlcpy() Tom Lane <tgl@sss.pgh.pa.us>
Re: Replace remaining StrNCpy() by strlcpy() Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Re: Replace remaining StrNCpy() by strlcpy() Tom Lane <tgl@sss.pgh.pa.us>
Re: Replace remaining StrNCpy() by strlcpy() Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Re: Replace remaining StrNCpy() by strlcpy() Tom Lane <tgl@sss.pgh.pa.us>
Re: Replace remaining StrNCpy() by strlcpy() Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Re: Replace remaining StrNCpy() by strlcpy() David Rowley <dgrowleyml@gmail.com>
I wrote:
> David Rowley  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 по дате отправления
От: Magnus Hagander
Дата:
От: Tom Lane
Дата:
FAQ