Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug report: memory corruption #179

Closed
AndreyMlashkin opened this issue Jul 14, 2022 · 5 comments
Closed

bug report: memory corruption #179

AndreyMlashkin opened this issue Jul 14, 2022 · 5 comments

Comments

@AndreyMlashkin
Copy link
Contributor

in the constructor of KDTreeSingleIndexAdaptor, you expect inputData lifetime should be longer rather then Adaptor itself, but it is not always true and user of the code can easily break it.

    KDTreeSingleIndexAdaptor(
        const Dimension dimensionality, const DatasetAdaptor& inputData,
        const KDTreeSingleIndexAdaptorParams& params = {}, Args&&... args)
        : dataset(inputData),
          index_params(params),
          distance(inputData, std::forward<Args>(args)...)
    {

for exmple, calling this would cause indefined behaviour:
ModelKDTreeIndex index(2, std::vector {}, nanoflann::KDTreeSingleIndexAdaptorParams(10));

@AndreyMlashkin
Copy link
Contributor Author

even worse thing just happened in my code: inputData was implicitly converted and a temporary object was passed to the constructor.
Could you please mark constructor explicit?

@AndreyMlashkin
Copy link
Contributor Author

@jlblancoc ping

@jlblancoc
Copy link
Owner

Merged #180. I'll however leave this one open to remember to add a comment to that ctor warning the users about expected lifetimes.
Thanks.

@AndreyMlashkin
Copy link
Contributor Author

Thanks!
Could you also ping me somehow, I will also create a new version of nanoflan in conan package manager.

@jlblancoc
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants