Re: [COMMITTERS] pgsql: StrNCpy -> strlcpy (not complete)

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: [COMMITTERS] pgsql: StrNCpy -> strlcpy (not complete)
Дата
Msg-id 200702110935.41769.peter_e@gmx.net
обсуждение исходный текст
Ответ на Re: [COMMITTERS] pgsql: StrNCpy -> strlcpy (not complete)  (mark@mark.mielke.cc)
Ответы Re: [COMMITTERS] pgsql: StrNCpy -> strlcpy (not complete)
Список pgsql-hackers
mark@mark.mielke.cc wrote:
> I think we had this discussion already. strncpy() copies N bytes,
> whereas strlcpy() copies only as many bytes as necessary. For short
> strings with larger buffers, strlcpy() wins. It's understood that
> in many cases in PostgreSQL, the expectation is for short strings,
> and it is not required for the later bytes to be '\0'.

You may also speculate that strncpy() is more optimized in some C 
libraries than strlcpy().  However, the changed cases are all 
uninteresting in terms of performance or fall under the short strings 
in long buffers case.

The remaining uses of StrNCpy() are either inner loops which need to be 
investigated, or it's not clear whether the zero-filling of strncpy() 
is required, or it's in a library were the libpgport linkages needs to 
be added.

The main idea here is to get this programming style out because it's 
become clear that people are very confused about how to use some of the 
other functions correctly.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: XML export
Следующее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: Ooops ... seems we need a re-release pronto