On Tue, May 6, 2008 at 10:21 AM, Jaroslav Hajek <[EMAIL PROTECTED]> wrote:
>  > On Tue, May 6, 2008 at 3:35 PM, Michael Goffioul
>  >  >  src/ann/bindings/tests/octave/

To run the octave based tests, you can go to ann-1.0/src

and run

make check

>  >

>  >  I looked further and while debugging, I found suspicious code
>  >  in octave_swig_packed::copy:
>  >
>  >  std::copy(&buf[0], &buf[sz], (char*)ptr);
>  >
>  >  While this looks nice, this code is accessing memory
>  >  outside the allocated area for buf: when sz == buf.size(),
>  >  then buf[sz] is outside the bounds of buf. When replacing
>  >  it with:
>  >
>  >  memcpy(ptr, &buf[0], sz);
>  >
>  >  everything works fine.
>  >
>

buf[sz] like this shouldn't dereference buf[sz]. 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.

The first two args to std::copy give a half-open range [first,last).

std::copy(&buf[0], &buf[sz], (char*)ptr);

is the same as

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

except the former is instantiated for char* rather than
vector::iterator. The latter may be more portable. I'll have a look at
the MSVC headers.

>  One can also safely use
>
>  std::copy(buf, buf+sz, (char*) ptr)
>
>  to stay within STL algorithms.
>  I'm sure that `buf+sz' is allowed; I don't know about `&buf[sz]'.
>  `buf[sz]' alone is definitely not allowed.

buf is an STL vector. buf+sz doesn't work. At least not in gcc.

>
>
>  >  Another source of null-referencing is in octave_swig_packed::print:
>  >  as "type" can be NULL, type->name is unsafe. One example of
>  >  such object is created in SWIG_Octave_SetModule.

I'll take a look at this later.

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
>  >
>
>
>
>  --
>  RNDr. Jaroslav Hajek
>  computing expert
>  Aeronautical Research and Test Institute (VZLU)
>  Prague, Czech Republic
>  url: www.highegg.matfyz.cz
>
>
>
>  -------------------------------------------------------------------------
>  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
>

-------------------------------------------------------------------------
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