ddemidov / mba

Scattered data interpolation with multilevel B-Splines
MIT License
73 stars 23 forks source link

Range check in multi_array #20

Closed czertyaka closed 2 years ago

czertyaka commented 2 years ago

https://github.com/ddemidov/mba/blob/420bc7f4d0717a1f66eee05f61122ff2dd28d65a/mba/mba.hpp#L96-L110

Got SEGFAULT due to acessing values in multi_array via operator[]. Somehow index appeared to be too large (still don't know how it happened).

Thread 1 received signal SIGSEGV, Segmentation fault.
(gdb) bt -full
#0  mba::detail::multi_array<double, 2>::operator() (this=0x2559bddadc8, i=...) at D:/Dev/mrl/mba/mba/mba.hpp:97
No locals.
#1  0x00007ff6a9fc1ab6 in mba::detail::control_lattice_dense<2u>::operator() (this=0x2559bddad80, p=...) at D:/Dev/mrl/mba/mba/mba.hpp:436
        w = -5.0494797734556483e-18
        d = {N = {_M_elems = {4, 4}}, i = {_M_elems = {0, 0}}, done = false, idx = 0}
        i = {_M_elems = {18446744073709551615, 274}}
        s = {_M_elems = {0.999999999999998, 0.064516129032256231}}
        f = 0
#2  0x00007ff6a9fc1285 in mba::MBA<2u>::operator() (this=0xaa1e1ff920, p=...) at D:/Dev/mrl/mba/mba/mba.hpp:751

Propose to use at() here so we can catch std::out_of_range in such cases.

ddemidov commented 2 years ago

Looks like a duplicate of #12

ddemidov commented 2 years ago

But since this is a frequent request, I've added an out of bounds check in dfb59ff6c7f285ebdff577e9dd2254d66db3964d.

czertyaka commented 2 years ago

Thanks a lot. My first reported issue, haven't figured out how it should work properly yet here on GitHub. I'll check previous issues more thoroughly next time :)