News for hackers. Stuff that matters.
Re:Simple Linux kernel memory corruption bug can lead to com... by throwaway81523 on Wednesday October 20, 2021 @03:56AM (#28927982)
> Huge. Only checking array bounds on every access degrades performance considerably.

I have not found this, at least in application code. There is usually at most a few percent different between v[i] and v.at(i) (the latter checks bounds) with C++ std::vector, for example. So I almost always use .at() these days, and it does catch bugs.

Re:Simple Linux kernel memory corruption bug can lead to com... by scns on Wednesday October 20, 2021 @04:19AM (#28928123)
Well, there is the rub. The safe thing to do is more verbose, the unsafe way is in muscle memory. Rust did it the other way around deliberately. But that is easy if you do a new design and don't need to retrofit a safe solution. No snark intended.
Re:Simple Linux kernel memory corruption bug can lead to com... by pjmlp on Wednesday October 20, 2021 @09:54AM (#28930712)
That is why one should always enable the compiler switches that turn operator[]() into at(), and then only disable them on case by case scenario, if proven worthwhile to do so.
Re:Simple Linux kernel memory corruption bug can lead to com... by gpderetta on Wednesday October 20, 2021 @04:42AM (#28928290)
wouldn't compiling with _GLIBCXX_ASSERTIONS or the corresponding for your compiler of choice be a better solution? It will also catch quite a few more issues (dereferencing null smart pointers, empty optionals, etc.), while being still relatively lightweight.
Re:Simple Linux kernel memory corruption bug can lead to com... by throwaway81523 on Wednesday October 20, 2021 @05:07PM (#28936634)
Thanks, I didn't know (or didn't remember) about this, but it's not clear from the docs that it bounds checks []. I don't find it difficult to use .at(). I'll try the debug mode too, but when I bother writing something in C++ it's usually because I actually care about its speed, so I don't want the overhead to be too bad.

https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros...

Re:Simple Linux kernel memory corruption bug can lead to com... by pjmlp on Wednesday October 20, 2021 @07:54AM (#28929591)
Not the OP, that is my approach, keep on the bounds checking settings from VC++ also in release builds.

And before STL was a thing, all the custom types I had were bounds checked by default.