On Tue, May 6, 2008 at 4:14 PM, Michael Goffioul
<[EMAIL PROTECTED]> wrote:
> On Tue, May 6, 2008 at 6:33 PM, Xavier Delacour
>
> <[EMAIL PROTECTED]> wrote:
>
> >  buf[sz] like this shouldn't dereference buf[sz].
>
>  I'm not following this sentence....

Sorry. I meant to say that buf[sz] should return a reference to
start_of_array + sz, but not actually read the memory at that
location.

>
>
>  >  Maybe it's a
>  >  difference between MS and gcc STL implementations (though I thought it
>  >  was standard.. do you have a segfault at this point?). buf[sz] ought
>  >  to return a reference, &buf[sz] converts it to a pointer.
>
>  Indeed, I get a segfault at this point. When debugging, I see that
>  vector<T>::operator[] is really executed with an out-of-bound index.
>  And this really dereference and invalid memory location. If you look
>  into MSVC header you find something like:
>
>         reference operator[](size_type _Pos)
>                 {       // subscript mutable sequence
>                 return (*(_Myfirst + _Pos));
>                 }

Huh. Well, I wouldn't expect this to "dereference"  (_Myfirst + _Pos),
by which I mean "read the byte from memory" any more than I would
expect

char* p = (char*) 0;
char& r = *p;

to crash (it doesn't, under gcc). Flipping through the standard for a
few minutes doesn't yield a clear answer, however the resident
language lawyer here suspects it isn't defined one way or the other..
along with my original usage of std::vector.

Anyway, I think the following form is the proper one,

std::copy(buf.begin(), buf.begin()+sz, (char*)ptr);

I'll update accordingly once I receive a patch from someone with the
various Windows related fixes (even if partial).

Thanks,
Xavier

>
>  Michael.
>

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Octave-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to