httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dean Gaudet <dgau...@arctic.org>
Subject Re: strncpy is evil
Date Tue, 23 Dec 1997 19:06:38 GMT


On Tue, 23 Dec 1997, Jim Jagielski wrote:

> Dean Gaudet wrote:
> > 
> > +
> > +char *strncpy(char *dst, const char *src, size_t len)
> > +{
> > +    char *d = dst;
> > +
> > +    for(;;) {
> > +	if (!len) break;
> > +	if (!(*d++ = *src++)) break;
> > +	--len;
> > +    }
> > +    return dst;
> > +}
> > 
> 
> Any reason why you didn't use a while?

Just 'cause ? :)  Actually I prefer the for(;;) {} loops with dozens of
breaks when the continuation expression is complex.

> This version NULL terminates the string as well, which violates
> standard strncpy but which you said would be cool.

Oh yeah I was just goofing around, if I do this for real I'll also go
whack every single occurance of strncpy in the code and replace it with
ap_copystr or something... I want to avoid a standard name on this one so
that folks know it has different semantics.

I'm not sure I'm advocating these for 1.3.  I'd love to get the
"non-aggressive" optimizations in though... by "aggressive" I mean ones
which are not necessarily right for all setups... like the mod_include one
;)

Dean



Mime
View raw message