At my tiny org, the core engine is C++ due to a compute heavy workload. I need to respond to NSA’s recommendation about replacing C++ with a memory safe language (I am not particularly interested in establishing whether the people who wrote the recommendation are qualified to do it).
My current lean is to come up with a set of simple rules to help make our codebase memory safe. I have basic familiarity with C++, so I need some help from this community. Here’s what I have so far
- No heap allocation ourselves. No new / delete
- No char* for string variables, only std::string
- Replace static arrays with std::array, dynamic arrays with std::vector
- Pointers to objects are okay since all objects are on the stack (even if the object itself is managing memory on the heap, like a vector). It’s okay to pass these pointers as arguments to functions, but not as a return value. (I guess I could change this one to “no pointers” and instead pass objects by reference where needed)
What else should I add to this list?