Attempt at avoiding falsely flagged buffer overruns#455
Conversation
src/annoylib.h
Outdated
| const double reallocation_factor = 1.3; | ||
| S new_nodes_size = std::max(n, (S) ((_nodes_size + 1) * reallocation_factor)); | ||
| void *old = _nodes; | ||
| void *new_nodes = NULL; |
There was a problem hiding this comment.
oops this was something that was irrelevant to this PR, let me revert
46a0ce6 to
113867c
Compare
eddelbuettel
left a comment
There was a problem hiding this comment.
Using MAX_ARRAY_SIZE should work, and I can test it.
|
Could we ever run over MAX_ARRAY_SIZE ? |
|
Oh, gosh, I had thought #define MAX_ARRAY_SIZE (1<<30)together with put massive arrays on the stack? Confused... |
No because the Node object is actually never allocated if you read the code. So it should be fine! |
|
Testing now at rhub. Old code gave Will know in a moment if this helps. Not a perfect test (as we don't have the exact setup CRAN uses). |
|
Part of me has the vague feeling that we once had a constant there, also got yelled at, and later went to |
I think it was zero for a long time. It's like the old saying that in computer science there's only three numbers, 0, 1, and n. And we went from 0 to 1 to now n :) |
|
Sadly it didn't yet work. |
|
Is it possible that the declaration needs to be changed in more places, e.g.: Line 517 in d6dc805 |
|
If I replace all declarations of Line 897 in d6dc805 However, I now see a new runtime error: the line referenced is: Line 662 in d6dc805 |
|
Good thinking about replacing the other assignments! I was rushing things before making dinner. @erikbern Any magic for that line 662? |
|
Turns out there's actually 4 places this had to be modified, and I had just fixed it in one of them. Can you check if it works now? Thanks! |
Actually this PR won't fix that issue, and I'm not sure how to even fix it. Some thoughts:
None of these are entirely trivial, but I think the last one is reasonably simple since there's only a few places where this really happens. I'll take a look at it in the next few days. |
|
Fair enough. I would be happy to see the current PR merged, as it does localize the UBSAN complaints to just the Hamming calculation, which is an improvement. I'd like to open a separate issue to cover the new misalignment problem, even if there isn't an obvious fix. |
|
Cool will handle the Hamming issue in a separate PR, thanks |
|
Thanks for your work on this @erikbern, it is much appreciated. |
|
Very much seconded. That was excellent help, and really timely :) |
Just a quick shot at addressing jlmelville/uwot#50