In this lesson, you will learn how to draft the design rationale required to justify defensive programming choices to auditors and certification bodies for safety-critical systems.
Beyond the "What": The "Why" of Defensive Design
When working on systems like ISO 26262 (automotive) or DO-178C (avionics), simply writing robust code is not enough. You must provide a Safety Case—a clear, documented argument that explains why your implementation is resilient against failures. If you implement Defensive Input Validation or Deterministic Memory Management, the documentation must explicitly tie those technical decisions to the potential hazards identified in your Failure Mode and Effects Analysis (FMEA).
Structuring the Design Rationale
Your rationale should follow a "Claim-Evidence-Argument" structure. Do not just document the function; document the safety justification.
Consider a simple sensor reading function:
/*
* Rationale:
* Hazard: Invalid sensor data leading to actuation error (FMEA-ID: SENS_04).
* Mitigation: Range-check inputs against hardware-defined physical limits.
* Requirement: SYS_REQ_42 (Input integrity).
*/
int32_t read_sensor_value(void) {
int32_t raw_val = adc_get_raw();
if (raw_val < MIN_PHYSICAL_LIMIT || raw_val > MAX_PHYSICAL_LIMIT) {
return ERR_INVALID_RANGE; // Graceful degradation path
}
return raw_val;
}
In your documentation, you must explicitly link the code block to the safety goal. An auditor doesn't just want to see the if statement; they want to see the cross-reference to your Fault Tree model proving that this specific check mitigates a top-level safety violation.
Why Documentation Matters
If a failure occurs, the documentation acts as your primary legal and technical defense. It demonstrates that you followed a methodical process:
- Hazard Identification: You recognized the risk of corrupt sensor data.
- Defensive Strategy: You implemented
Defensive Input Validationand defined aGraceful Degradation Strategy. - Verification Link: You cited the static analysis or formal verification result that proves the bounds checking cannot be bypassed.
Without this rationale, even the most secure code appears arbitrary to a safety auditor. Documentation transforms a "coding preference" into a "verifiable safety control."
Key Takeaway: A defensive design choice is only as valuable as the documented argument that links it directly to an identified safety hazard and a formal requirement.