Re: strncpy is not a safe version of strcpy - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: strncpy is not a safe version of strcpy
Date
Msg-id 20131115152744.GB6220@eldon.alvh.no-ip.org
Whole thread Raw
In response to Re: strncpy is not a safe version of strcpy  (Kevin Grittner <kgrittn@ymail.com>)
Responses Re: strncpy is not a safe version of strcpy  (Kevin Grittner <kgrittn@ymail.com>)
List pgsql-hackers
Kevin Grittner escribió:
> Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
> 
> > This code should probably be using namecpy().  Note namecpy()
> > doesn't memset() after strncpy() and has survived the test of
> > time, which strongly suggests that the memset is indeed
> > superfluous.
> 
> That argument would be more persuasive if I could find any current
> usage of the namecpy() function anywhere in the source code.

Well, its cousin namestrcpy is used in a lot of places.  That one uses a
regular C string as source; namecpy uses a Name as source, so they are
slightly different but the coding is pretty much the same.

There is a difference in using the macro StrNCpy instead of the strncpy
library function directly.  ISTM this makes sense because Name is known
to be zero-terminated at NAMEDATALEN, which a random C string is not.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: strncpy is not a safe version of strcpy
Next
From: Stephen Frost
Date:
Subject: Re: strncpy is not a safe version of strcpy