httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Jagielski <>
Subject Re: [PATCH] ap_cpystrn() function (replace strncpy)
Date Fri, 26 Dec 1997 19:57:09 GMT
Dean Gaudet wrote:
> On Fri, 26 Dec 1997, Jim Jagielski wrote:
> > I struggled about doing this, ie: whether the NULL should be
> > placed at dst+len or dst+len-1 In the code, we generally did the -1
> > during the call so placing it at dst+len made sense since it
> > didn't leave a extra unused byte at end. Also, if we use 'len' as
> > the # of chars to copy, it ensures that it's NULL terminated
> > since it'll shove the \0 where it belongs. Your version instead
> > uses len as the size of dst, which is fine, but not the same.
> ap_snprintf treats len as the size of dst... it'd be nice to be
> consistent.  That's my reasoning. 

Since we are rolling our own, that's fine...
> Actually with strncpy it doesn't matter if you use sizeof(foo)-1 in
> strncpy followed by dst[sizeof(foo)-1] = 0; or if you use sizeof(foo)
> unmodified in strncpy.  The reason for the -1 is to save one extra byte
> copy that's not needed.  You'll notice some of the calls don't have the
> -1. 

If we want to copy only 5 chars, strncpy is called as strncpy(...,5);
With ours, if we want to copy at most 5 chars, we would call
ap_cpystrn(....,6). This may confuse people. However, since it's used
more to prevent buffer overrun, your point is valid.

I'll post a version that uses len=buffer-size
      Jim Jagielski            |       jaguNET Access Services           |
            "Look at me! I'm wearing a cardboard belt!"

View raw message