Re: Coding note: truncating with strlcpy() is not such a hot idea - Mailing list pgsql-hackers

From Noah Misch
Subject Re: Coding note: truncating with strlcpy() is not such a hot idea
Date
Msg-id 20151222065348.GA2556345@tornado.leadboat.com
Whole thread Raw
In response to Coding note: truncating with strlcpy() is not such a hot idea  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Mon, Dec 21, 2015 at 03:47:56PM -0500, Tom Lane wrote:
> 1. Using strlcpy to copy from sources that are not known null-terminated
> is outright unsafe: someday, you'll fall off the end of memory and
> SIGSEGV.
> 
> 2. Even with a known null-terminated string, using strlcpy to chop small
> pieces out of it is not bright, because each call will traverse all the
> rest of the input.  This means for example that extracting N words out
> of a long string will spend O(N^2) time in strlcpy.

Good points.



pgsql-hackers by date:

Previous
From: Amit Langote
Date:
Subject: Re: Foreign join pushdown vs EvalPlanQual
Next
From: Michael Paquier
Date:
Subject: Re: WIP: Fix parallel workers connection bug in pg_dump (Bug #13727)