Reply to post:

Revealed: The 25 most dangerous software bug types – mem corruption, so hot right now

_LC_

The std::string class can return a null-terminated string for you. This is guaranteed to work (no memory allocation). You can test the string for emptiness in various ways. The string class stores the length.

You are basically criticizing C and blaming this on C++, as you are talking about C interfaces. You have to feed those interfaces the same way from Pascal; no difference there.

Since C++17, there's also the std::string_view class, which is a "low cost" wrapper to keep arrays safe, even C strings.

Again, you can do things wrong if you want, but only if you ignore all advises.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon