hungpham2511 / toppra

robotic motion planning library
https://hungpham2511.github.io/toppra/index.html
MIT License
603 stars 167 forks source link

Incorrect variable used in seidel.cpp, causing memory errors #189

Closed stevegolton closed 2 years ago

stevegolton commented 2 years ago

Describe the bug It appears a loop counter variable i shadows another loop counter variable with the same name, used to iterate an outer loop. This would be fine, but the outer loop variable is used in the scope of the inner loop as well, so the wrong variable is being used erroneously. This most likely results in the wrong behaviour, but can also occasionally result in reading off the end of the vector and unallocated memory being accessed, which is reported by valgrind as an invalid memory access. This usually has no immediate effect but can cause crashes further down the line, especially when memory is being freed. https://github.com/hungpham2511/toppra/blob/a70f6a217ddf20c42b62471ab52ce16884a320c1/cpp/src/toppra/solver/seidel.cpp#L326-L327

I'm not 100% sure of the solution, but I think it should probably look something like this instead:

for (int k = 0; k < m_A[i].rows(); ++k)
      m_index_map[k] = k;

Version Tip of develop.