httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dean Gaudet <>
Subject Re: [PATCH] ap_cpystrn() function, replace strncpy() Take II
Date Sat, 27 Dec 1997 06:05:48 GMT

On Fri, 26 Dec 1997, Jim Jagielski wrote:

> Dean Gaudet wrote:
> > 
> > The reason I initialized "end = dst + dst_size - 1" after the dst_size ==
> > 0 test is that if dst_size == 0 then you've set end = &dst[-1], which
> > isn't always valid ansi C...
> I'm almost sure that isn't true. After all, we are simply setting
> a pointer value; there is no sense at all of dst's "allocation";
> it's simple pointer usage. We just set it to a value, but never use
> it. I could be wrong about this, but I don't think it's anymore
> illegal than setting a pointer past the block; True, by doing so
> and then using it you're in trouble-land, but setting the pointer
> is OK.

The only case which I can think of where doing &foo[-1] is "bad" is on
segmented architectures like i286.  In that case it's quite easy for
"&foo[-1] > &foo[0]" to be true when the offset portion of &foo[0] is 0
(in segmented archs a pointer is a segment:offset pair), in this case
&foo[-1] wraps around to the top of the segment and is likely an invalid
pointer (and will raise a protection fault).  But even then for anything
which is palloc()d or on the stack this isn't going to be the case
(because there's always gunk in front of it, hidden)... so yeah I was just
being a nitpick. 


View raw message