httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Jagielski <...@jaguNET.com>
Subject Re: strncpy is evil
Date Tue, 23 Dec 1997 15:24:41 GMT
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?
> 
> char *ap_strncpy(char *dst, const char *src, size_t len)
> {
>    char *d = dst;
>    char *end = dst+len;
>    
>    while ( ; len && (*d++ = *src++) ; len-- )
>      ;
> 
>    if (d >= end)
>      end = '\0';
> 
>    return dst;
> }
> 

Ack.... stupid, stupid, stupid... lack of freakin' caffeine :/

It should be, of course, while->for and the right *end


-- 
====================================================================
      Jim Jagielski            |       jaguNET Access Services
     jim@jaguNET.com           |       http://www.jaguNET.com/
            "Look at me! I'm wearing a cardboard belt!"

Mime
View raw message