Hacker News new | ask | show | jobs
by eklitzke 1320 days ago
Sure but you wouldn't be reading a password into a std::array or std::vector in C++, you'd be reading into a std::string or possibly something like a std::stringstream. And both of those containers will handle sizing and reallocation for you.

If your point is that C++ lets you do unsafe things then yes, of course it does. But so does Rust.

1 comments

I think you may be misinterpreting my comment a bit, I did not mean that C++ was bad here, but rather a large improvement.

My point was that in C++ (and others) you can completely prevent this entire class of errors by using the standard containers. std::string, just like std::vector and std::array provide the checked access methods which will prevent buffer overflows when used.

Almost every language other than C lets you access elements of a container safely, and oftentimes even the default methods for access are safe! In C++ there are compiler flags that make operator[] safe by default for all of the std containers too.