Re: decrement past beginning is valid?

From: Mike Wahler (mkwahler_at_mkwahler.net)
Date: 11/05/04


Date: Fri, 05 Nov 2004 03:32:10 GMT


"Watson Davis" <watson@watsonmusic.com> wrote in message
news:Xns9597AC4FD1805thepencilneckyahooco@206.66.12.201...
> Francis Glassborow <francis@robinton.demon.co.uk> wrote in
> news:c7mowqa96riBFwfy@robinton.demon.co.uk:
>
> > In article <Xns959756278EEC1thepencilneckyahooco@206.66.12.208>,
> > Watson Davis <watson@watsonmusic.com> writes
> >>Pedro Graca <hexkid+usenet@gmail.com> wrote in
> >>news:slrncokhqt.9tq.hexkid+usenet@ID-203069.user.uni-berlin.de:
> >>
> >>> I know that incrementing a pointer one past the end of the array is
> >>> valid (as long as I don't dereference it).
> >>>
> >>> Is it valid to decrement before beginning of array?
> >>
> >>Sure. It's just a pointer and you can pretty much increment and
> >>decrement that thing all over the place without a problem. Well... if
> >>you ASSIGN something to the wrong place you can create some pretty
> >>magnificent problems...
> >
> > No, creating an address that is not owned by your process can and does
> > cause your program to abort on some platforms. The dispensation for
> > one-past-the-end is exactly a requirement on compilers for such
> > platforms to ensure that that address is owned by the process and so
> > does not cause the program to abort.
>
> You are misinterpreting my point.

I think he's *corrected* your point, which was incorrect.
One cannot indiscriminately increment or decrement a pointer
and expect nothing to go wrong. One must follow the rules.

-Mike



Relevant Pages

  • Re: decrement past beginning is valid?
    ... It's just a pointer and you can pretty much increment and ... >>decrement that thing all over the place without a problem. ... > cause your program to abort on some platforms. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Thou shalt have no other gods before the ANSI C standard
    ... Because of these two platforms ... > The C standard does allow memcpy of pointer objects. ... New compiler development for such platforms is not a poor economic ...
    (sci.crypt)
  • Re: Why does rewind() ignore errors?
    ... promise that memsetting any scalar to zero on their implementations ... YOU can assume that all-zero-bits is a valid null pointer ... platforms where it is true. ... The C standard allows C implementations to run programs on those rare ...
    (comp.std.c)
  • Re: OpenSSL Hacks
    ... possible on many platforms when a null pointer is used as though it ... to denial-of-service are a crucial security goal. ... If you found a honest-to-goodness exploitable security vulnerability, ...
    (sci.crypt)
  • Re: [RFC,PATCH 0/7 v2] Common struct clk implementation
    ... You're still only touching the "easy" platforms (as I pointed out ... having those platforms use a pointer to a set of clk operations ... for one OMAP CPU - if you include all OMAP CPUs which share the same ...
    (Linux-Kernel)