Re: Replace remaining StrNCpy() by strlcpy()

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Replace remaining StrNCpy() by strlcpy()
Дата
Msg-id 2268534.1596456766@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()  (David Rowley <dgrowleyml@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Magnus Hagander
Дата:
Сообщение: Re: [PATCH] Add section headings to index types doc
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [PATCH] Add section headings to index types doc