This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Using strlcpy if target OS allows it
On Thu, Apr 21, 2005 at 02:31:28AM +0200, Marc Espie wrote:
> On Wed, Apr 20, 2005 at 06:18:31PM -0500, Aaron W. LaFramboise wrote:
> > Marc Espie wrote:
> >
> > > The linker now warns about uses of strcpy, which means that the whole
> > > libstdc++ testsuite fails on OpenBSD now.
> >
> > If you're just trying to fix the testsuite failures, perhaps you could
> > use the gcc-dg-prune callback to ignore this warning?
> >
>
> As far as the testsuite goes, yep.
> In general, having the library warn is a major annoyance...
> well, it's fixed on my box now by sprinkling strlcpy all over the place,
> but having yet another patch to maintain internally is stuff I could live
> without...
There appear to be only four calls of strcpy in the library itself
(as opposed to the testsuite). All four take this exact form:
char* __sav = new char[std::strlen(__old) + 1];
std::strcpy(__sav, __old);
Perhaps the V3 maintainers could be persuaded to accept a patch that
replaces all four with a call to
inline char* __cstring_duplicate(const char* __old) {
unsigned __size = std::strlen(__old) + 1;
char* __sav = new char[__size];
return std::strcpy(__sav, __old);
}
This would have maintainance advantages, as four identical code sequences
become one.
Then for OpenBSD you only need a simple patch:
- return std::strcpy(__sav, __old);
+ strlcpy(__sav, __old, __size);
+ return __sav;