liveBook · Manning

Dynamic analysis

As explained in Memory Safe C++

Analysis of software behavior by executing the software and observing its runtime properties.

A misconfigured sensor can expose a memory defect that ordinary tests miss. Dynamic analysis tests code while it runs, observing defects in the execution paths and inputs exercised. In safety-critical C++, it is one part of a systematic memory-safety process, alongside safe design patterns, static analysis, and code review. section 1.7 section 1.10

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 is copied into a 32-byte array without a bound check; the label length determines where a defect appears. section 1.7

Test the boundary

Run the test suite with AddressSanitizer (ASan) enabled and exercise labels of 31, 32, and 33 bytes. At 32 bytes, ASan reports the missing terminator at LogReading; at 33 bytes, it reports the out-of-bounds copy at std::copy. A 31-byte label produces correct output and no ASan report, even though the code remains defective. Tests using only short labels can therefore leave the dangerous cases unexercised. section 1.7

A clean runtime report is evidence about the executions tested, not proof that every input is safe. Use boundary value analysis to choose revealing cases, and combine runtime testing with static analysis and review. section 1.7 section 1.10

How Memory Safe C++ covers it

How deep it goes
Explains an AddressSanitizer test workflow and its dependence on exercised inputs, without detailing tool internals.
Examples
Uses a sensor label copied into a 32-byte array to contrast 31-, 32-, and 33-byte test inputs.
What you can do after
Apply it via AddressSanitizer by running tests with boundary inputs and interpreting where reports appear.
How it connects
Connects runtime testing with boundary value analysis, static analysis, and code review.

Also explained in

Compare how 3 books explain dynamic analysis →

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.