liveBook · Manning

Safety culture

As explained in Memory Safe C++

A safety culture is a shared team and organizational commitment to prioritizing safety and best practices.

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

How Memory Safe C++ covers it

How deep it goes
Defines three foundations and outlines a process from design choice through review, with automated checks supporting consistent practice.
Examples
Uses a patient-monitoring sensor label copied into a fixed-size buffer to illustrate a missing null terminator.
What you can do after
Evaluate safety culture as a shared commitment supported by knowledge, discipline, automated checks, and review.
How it connects
Connects safety culture to memory safety, buffer overflows, use-after-free, automated checks, and review.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Memory Safe C++. The section links point to the parts of the book it draws on.