Git Product home page Git Product logo

Comments (6)

nmoehrle avatar nmoehrle commented on September 13, 2024

The second parameter to the sort function is an beyond the end iterator, so the off by one "access" in this case intentional. However, a more correct solution here, and in a couple of other places in this lib, would be indices->begin() + node.last. I am not sure when I'll have time to change that so I would be happy for a PR if you have the time ;-)

from libacc.

allo- avatar allo- commented on September 13, 2024

The problem is, that indices[node.last] is no iterator here, but a std::vector access, so it throws an exception. As far as I understand the code, you're accessing the last+1 element and then take the address (which probably is a pointer to the underlying array).

I will have look if indices.begin() + node.first, indices.begin()+node.last is the correct range for the iterator.

from libacc.

nmoehrle avatar nmoehrle commented on September 13, 2024

I know that indices[node.last] would be an out of bounds access, but depending on the compiler you don't need to access an element to take its address. But after writing this I have to agree that the code is broken considering that it relies on a compiler "optimization".

from libacc.

allo- avatar allo- commented on September 13, 2024

I need to use MSVC here and it breaks.
But looking at it, it seems that std::sort uses the points like an iterator, because both "*it" and "it++" are working on pointers as on iterators, but probably it is not meant to work on something else than iterators.

from libacc.

nmoehrle avatar nmoehrle commented on September 13, 2024

A pointer is an iterator, it is even a RandomAccessIterator since iterators are just concepts and a pointer implements all necessary functions to be classified as such.

A RandomAccessIterator is a BidirectionalIterator that can be moved to point to any element in constant time.
A pointer to an element of an array satisfies all requirements of RandomAccessIterator
http://en.cppreference.com/w/cpp/concept/RandomAccessIterator

Apart from that &vec[idx] is incorrect for (idx >= vec.size()) because it can be broken down to &(vec[idx]). I guess it never was an issue for me because the gcc stl has not bounds check on the array access operator and I never use the value of vec[idx] so the address of was optimized.

from libacc.

allo- avatar allo- commented on September 13, 2024

Fixed in #4

from libacc.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.