In a patient monitoring system, a 32-character sensor label can fill a fixed-size buffer without leaving a null terminator. A logging function may then read past the buffer while looking for one. Preventing such defects requires more than one careful developer. section 1.7 section 1.7
Safety culture is a team and organizational commitment to safety and best practices over shortcuts. It supports two other foundations of memory-safe C++: knowledge of hazards such as buffer overflows and use-after-free, and discipline to apply safe practices even under deadline pressure. section 1.7
A systematic process carries that commitment from design choices through review. Automated checks help sustain discipline because they do not depend on someone remembering to run them under pressure; review catches problems earlier stages miss. section 1.7
Listing 1.1 Sensor label copy without bounds check
void ProcessSensorReading(std::span<const std::uint8_t> raw_data) {
constexpr std::size_t kMaxLabelLength = 32; #A
std::array<char, kMaxLabelLength> sensor_label{}; #B
auto reading = ParseSensorData(raw_data);
std::copy(reading.label.begin(), #C
reading.label.end(),
sensor_label.begin());
LogReading(sensor_label.data(), reading.value); #D
}
The sensor-label listing shows how copying into a fixed-size buffer can leave logging without a null-terminated string. section 1.7
