Using strlcpy if target OS allows it
Mon May 2 21:09:00 GMT 2005
> On Thu, 21 Apr 2005, it was written:
> > Date: Thu, 21 Apr 2005 13:40:29 -0700
> > From: Joe Buck <Joe dot Buck at synopsys dot COM>
> > To: "J dot T dot Conklin" <jtc at acorntoolworks dot com>
J.T. Conklin wrote:
> > > If a change is made, why not replace the strcpy() with a memcpy()? As
> > > it is, strcpy() is copying until it reaches the terminating null char,
> > > even though we already know how many bytes to copy. memcpy() is often
> > > more efficent than strcpy as well, even those implementations that go
> > > to Herculean efforts to do only word-aligned read/writes.
> > Good point. That would be a small (probably negligle) performance
> > improvement and would get rid of the need to patch OpenBSD (other than the
> > test suite issue). Perhaps some interested party would like to make a patch?
On Mon, May 02, 2005 at 10:41:23PM +0200, Magnus Fromreide wrote:
> I think the folowing is the patch you were asking for, but see below for
> further comments.
[ patch of installed headers removed ]
I'm for a patch of that form (I did not study it, and someone with the
appropriate authority must approve, but I like the idea).
> Here follows the questionable part.
> I am not at all certain about which of the uses of strcpy in the testsuite
> that were intentional.
[ patch of testsuite ]
I would be much more cautious about patching the testsuite. I'd like to
see OpenBSD using the same libstdc++ as the rest of us, but I care much
less if they need local patches to ignore extra warnings from the
testsuite. As J.T. points out, use of memcpy when we already have
computed the string length is a (possibly insignificant, but real)
performance win, so it doesn't just silence a poorly-considered warning.
More information about the Libstdc++