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

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: mark(at)mark(dot)mielke(dot)cc
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [COMMITTERS] pgsql: StrNCpy -> strlcpy (not complete)
Date: 2007-02-11 08:35:41
Message-ID: 200702110935.41769.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

mark(at)mark(dot)mielke(dot)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/

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Magnus Hagander 2007-02-11 11:59:26 pgsql: Fix for early log messages during postmaster startup getting lost
Previous Message Tom Lane 2007-02-11 06:27:17 Re: [COMMITTERS] pgsql: StrNCpy -> strlcpy (not complete)

Browse pgsql-hackers by date

  From Date Subject
Next Message Andreas Kretschmer 2007-02-11 08:47:16 Re: [ADMIN] Priorities for users or queries?
Previous Message Benjamin Arai 2007-02-11 08:34:51 Re: Priorities for users or queries?