Chapter 2: Standards, coding guidelines, and memory safety
This introduction explains why C++ compilation alone cannot ensure safety and how standards, coding guidelines, and independent assessment complement it.
After this chapter you will be able to
- Limits of compiler checks. Explain why a program that conforms to the C++ standard can still have memory safety failures.
- Safety assurance framework. Describe how safety standards, coding guidelines, and independent assessment work together in safety-critical development.
- Reasons for safety standards. Explain why safety-critical industries use shared standards, including their role in predictability, legal compliance, and comparable safety evidence.
- Risk classification and lifecycle. Describe how standards classify safety functions or software items by failure risk and define development phases and required activities.
- Traceability and safety evidence. Explain bidirectional traceability and describe the documented evidence a project must produce.
- Automotive safety risk levels. Explain ISO 26262’s automotive scope and how its risk assessment determines ASIL or QM.
- ASIL effects on development. Explain how the assigned ASIL affects C++ implementation and verification within the software V-model.
- MC/DC coverage principle. Explain what MC/DC test cases demonstrate about conditions in a decision and how MC/DC compares with the other listed coverage metrics.
- Medical software lifecycle processes. Explain what IEC 62304 governs and how its lifecycle processes relate to the manufacturer's requirements.
- Risk based safety classification. Explain how risk management determines a software item's safety class and how that class affects development work, including for Class C.
- Railway standards family. Distinguish EN 50716's software scope from the roles of EN 50126 and EN 50129.
- Software integrity level inheritance. Explain the software integrity levels and how the required level is inherited from system-level safety analysis.
- Software lifecycle V-model. Describe the V-model structure of the EN 50716 software lifecycle.
- Objective-Based Airworthiness Assurance. Explain how DO-178C supports airborne software airworthiness while allowing different development strategies.
- Severity-Based Assurance Levels. Describe how failure severity determines the Development Assurance Level and the rigor of safety demonstration, using the ends of the scale.
- DO-178C Process Groups. Describe the roles of planning, development, and integral processes in DO-178C.
- Risk Based Integrity Levels. Explain how hazard assessment determines a Safety Integrity Level and how the level affects safety techniques and architecture.
- Software Lifecycle Requirements. Describe how IEC 61508 Part 3 addresses the software lifecycle, verification, documentation, tools, and modifications.
- Fault Avoidance and Control. Distinguish preventing software faults during development from detecting and responding to failures during operation.
- Guidelines and certification evidence. Explain how coding guidelines complement safety standards and support certification.
- MISRA and AUTOSAR relationship. Describe MISRA C++:2023 and its relationship to AUTOSAR C++14.
- Security guideline project selection. Distinguish CERT C++ from MISRA C++ and explain which guidelines the section recommends for a new project with security exposure.
- Standards to verification chain. Explain how safety standards, coding guidelines, and verification work together toward memory-safe C++ code.
- Spatial and temporal safety. Distinguish spatial from temporal memory safety and explain why both matter for complete memory safety.
- Spatial violation and effects. Explain what makes an access a spatial memory violation and describe its possible behavior using the ten-element buffer example.
- Explicit bounds checking. Describe how the checked example prevents an out-of-bounds write and handles an invalid index.
- Array initialization and indexing. Distinguish zero-initializing a std::array from checking its indices, and explain why buffer[15] remains unsafe without the explicit check.
- Temporal memory safety violations. Distinguish temporal violations from spatial violations and explain why accessing a freed object is a temporal violation.
- Use-after-free undefined behavior. Explain what can happen when the freed integer is dereferenced and what the differing results and warnings show.
- Unique pointer lifetime ownership. Describe how the unique smart pointer prevents the illustrated use-after-free, and explain why its dereferences are not always safe.
- Combined memory safety requirements. Explain why a memory access must satisfy both spatial and temporal safety, and what happens if either requirement fails.
- SensorBuffer paired checks. Trace how the SensorBuffer example checks lifetime and bounds before accessing an element, and explain why neither check alone is sufficient.
- Reliability and certification impacts. Explain how memory safety violations affect reliability and stability, and why unpredictable behavior blocks safety-critical certification.
- Exploitable security vulnerabilities. Distinguish security vulnerabilities from reliability failures and explain how their impacts can overlap.
- Profile guarantees and process. Explain what a safety profile guarantees and how its approach differs from process-based defense in depth.
- Superset and subset mechanism. Describe the two halves of subsetting a superset of ISO C++ and how they work together to support a profile's guarantees.
What it builds on
- Memory safety challenges (chapter 1) · The earlier discussion of C++ memory safety challenges provides context for compiler limitations.
Section by section
Introduction
This introduction explains why C++ compilation alone cannot ensure safety and how standards, coding guidelines, and independent assessment complement it.
- Limits of compiler checks: Explain why a program that conforms to the C++ standard can still have memory safety failures.
Why it matters: Clean compilation is not by itself evidence that a safety-critical program is memory-safe. - Safety assurance framework: Describe how safety standards, coding guidelines, and independent assessment work together in safety-critical development.
Why it matters: These complementary practices provide safety assurance beyond what the C++ language alone can establish.
Key terms: C++ standard, memory safety failures, runtime values, data races, safety standards, coding guidelines, certification, independent assessor, evidence
2.1 The safety standards
This section explains why safety standards are needed and the requirements they share across industries.
- Reasons for safety standards: Explain why safety-critical industries use shared standards, including their role in predictability, legal compliance, and comparable safety evidence.
Why it matters: Standards make safety a shared, demonstrable undertaking rather than a matter of individual discipline. - Risk classification and lifecycle: Describe how standards classify safety functions or software items by failure risk and define development phases and required activities.
Why it matters: These shared requirements connect the risk of failure to a defined development process. - Traceability and safety evidence: Explain bidirectional traceability and describe the documented evidence a project must produce.
Why it matters: Traceability links safety concerns to implementation and tests, while documented evidence supports the system's safety for its intended use.
Key terms: safety standards, compliance, shared framework, risk classification, Automotive Safety Integrity Level, software safety class, defined development lifecycle, hazard analysis, verification, bidirectional traceability
2.1.1 Automotive — ISO 26262
This section explains automotive functional safety under ISO 26262, how ASIL risk levels affect C++ development, and what MC/DC verification demonstrates.
- Automotive safety risk levels: Explain ISO 26262’s automotive scope and how its risk assessment determines ASIL or QM.
Why it matters: The assigned risk level connects a vehicle hazard to the safety requirements governing its software. - ASIL effects on development: Explain how the assigned ASIL affects C++ implementation and verification within the software V-model.
Why it matters: An ASIL affects both how you write vehicle software and the evidence needed to verify it. - MC/DC coverage principle: Explain what MC/DC test cases demonstrate about conditions in a decision and how MC/DC compares with the other listed coverage metrics.
Why it matters: MC/DC gives a concrete meaning to the stricter verification associated with higher safety levels.
Key terms: ISO 26262, functional safety, Automotive Safety Integrity Levels, ASIL, QM, severity, V-model, software unit design and implementation, structural coverage, verification independence
2.1.2 Medical devices — IEC 62304
This section explains how IEC 62304 structures medical-device software development around risk-based safety classes.
- Medical software lifecycle processes: Explain what IEC 62304 governs and how its lifecycle processes relate to the manufacturer's requirements.
Why it matters: This distinction shows what the standard contributes to a medical-device software project. - Risk based safety classification: Explain how risk management determines a software item's safety class and how that class affects development work, including for Class C.
Why it matters: The potential harm from a software failure shapes the rigor of the development process.
Key terms: IEC 62304, lifecycle processes, activities, tasks, risk management, ISO 14971, software safety class, Class C, traceability
2.1.3 Railway — EN 50716:2023
This section explains how EN 50716 fits into railway safety standards and governs software integrity and development.
- Railway safety principles: Describe the safety principles carried from mechanical and relay-based railway systems into software.
Why it matters: Railway software safety builds on principles established before software controlled these systems. - Railway standards family: Distinguish EN 50716's software scope from the roles of EN 50126 and EN 50129.
Why it matters: Knowing the standards' different scopes helps place software requirements within the wider railway safety context. - Software integrity level inheritance: Explain the software integrity levels and how the required level is inherited from system-level safety analysis.
Why it matters: A software team's required integrity level comes from the safety function it implements, not an isolated software-level choice. - Software lifecycle V-model: Describe the V-model structure of the EN 50716 software lifecycle.
Why it matters: The V-model connects the development lifecycle with corresponding verification activity. - Integrity level technique groupings: State how EN 50716 groups required techniques across software integrity levels.
Why it matters: The standard groups its required techniques by pairs of integrity levels.
Key terms: fail-safe design, proven-in-use components, independent verification, EN 50716, EN 50126, EN 50129, RAMS, signaling, rolling stock, Basic Integrity
2.1.4 Aerospace — DO-178C
This section introduces DO-178C’s objective-based approach to airborne software assurance, its severity-based assurance levels, and its development and verification processes.
- Objective-Based Airworthiness Assurance: Explain how DO-178C supports airborne software airworthiness while allowing different development strategies.
Why it matters: This distinction explains how teams can tailor development without relaxing safety assurance. - Severity-Based Assurance Levels: Describe how failure severity determines the Development Assurance Level and the rigor of safety demonstration, using the ends of the scale.
Why it matters: The level links the consequences of failure to how rigorously safety must be demonstrated. - DO-178C Process Groups: Describe the roles of planning, development, and integral processes in DO-178C.
Why it matters: The process groups show how producing software is accompanied by ongoing assurance activities. - DAL A Decision Coverage: State what Modified Condition/Decision Coverage requires at DAL A.
Why it matters: MC/DC is a specific additional coverage requirement for the most consequential assurance level.
Key terms: DO-178C, objective-based approach, software airworthiness, Development Assurance Level, DAL, failure analysis, ARP4754A/B, planning process, development process, integral processes
2.1.5 Industrial — IEC 61508
This section introduces IEC 61508’s industrial safety scope, risk-based integrity levels, and software requirements.
- Industrial Standard Foundation: Describe the scope and foundational role of IEC 61508.
Why it matters: This places industrial software requirements in the context of a broader, lifecycle-wide safety standard. - Risk Based Integrity Levels: Explain how hazard assessment determines a Safety Integrity Level and how the level affects safety techniques and architecture.
Why it matters: The integrity level connects the assessed hazard to the rigor of the safety approach. - Software Lifecycle Requirements: Describe how IEC 61508 Part 3 addresses the software lifecycle, verification, documentation, tools, and modifications.
Why it matters: Safety requirements extend beyond writing code to testing, evidence, tools, and subsequent changes. - Fault Avoidance and Control: Distinguish preventing software faults during development from detecting and responding to failures during operation.
Why it matters: A safety approach needs both prevention during development and a response when failures occur in operation.
Key terms: IEC 61508, E/E/PE, safety-related systems, Safety Integrity Level, SIL, failure analysis, formal methods, static analysis, MC/DC coverage, IEC 61508 Part 3
2.2 C++ coding guidelines in practice
This section explains how C++ coding guidelines support certification and compares the major guidelines used in safety-critical projects.
- Guidelines and certification evidence: Explain how coding guidelines complement safety standards and support certification.
Why it matters: This connects concrete coding rules to the evidence needed for certification. - MISRA and AUTOSAR relationship: Describe MISRA C++:2023 and its relationship to AUTOSAR C++14.
Why it matters: This helps you recognize the current cross-industry standard and understand older automotive references. - Security guideline project selection: Distinguish CERT C++ from MISRA C++ and explain which guidelines the section recommends for a new project with security exposure.
Why it matters: This gives you a practical starting point for choosing guidelines when safety and security both matter. - High Integrity C++ focus: Describe the focus and typical adoption of High-Integrity C++.
Why it matters: This helps distinguish a domain-focused guideline from MISRA's broader cross-industry use. - JSF C++ historical role: Explain why JSF C++ is historically significant but not used for new projects.
Why it matters: This explains why an important historical avionics standard may appear in legacy work but is not the modern choice.
Key terms: safety standards, coding guidelines, static and dynamic analysis, auditable evidence, MISRA C++:2023, AUTOSAR C++14, C++17, safe language subset, CERT C++, Common Weakness Enumeration
2.3 From standards to memory-safe C++
This section connects safety standards, coding guidelines, code, and verification in the effort to prevent memory safety violations.
- Standards to verification chain: Explain how safety standards, coding guidelines, and verification work together toward memory-safe C++ code.
Why it matters: This connection shows how standards and guidelines contribute to preventing dangerous memory defects.
Key terms: safety standards, coding guidelines, verification, memory safety violations
2.4 Type of memory safety violations
This section introduces spatial and temporal memory safety and notes an alternative, broader classification of memory safety bugs.
- Spatial and temporal safety: Distinguish spatial from temporal memory safety and explain why both matter for complete memory safety.
Why it matters: The distinction gives you two complementary questions to ask about memory access. - Broader bug classification: Describe the broader classification of memory safety bugs attributed to Google's Secure by Design paper.
Why it matters: It shows that some treatments classify memory safety more broadly than the two dimensions emphasized here.
Key terms: spatial memory safety, temporal memory safety, complete Memory Safety, type, initialization, data-race safety
2.4.1 Spatial memory safety (The “where” question)
This section explains spatial memory violations, their unpredictable effects, and how explicit bounds checking prevents them.
- Spatial violation and effects: Explain what makes an access a spatial memory violation and describe its possible behavior using the ten-element buffer example.
Why it matters: An access can be invalid even when the address exists and the program does not immediately crash. - Explicit bounds checking: Describe how the checked example prevents an out-of-bounds write and handles an invalid index.
Why it matters: Checking before an access prevents the invalid write rather than relying on a crash to reveal it. - Array initialization and indexing: Distinguish zero-initializing a std::array from checking its indices, and explain why buffer[15] remains unsafe without the explicit check.
Why it matters: A better-initialized container does not by itself make every indexed access safe.
Key terms: spatial violations, undefined behavior, boundaries, bounds checking, buffer.size(), invalid indices, std::array, operator[], overflow
2.4.2 Temporal memory safety (The “when” question)
This section explains temporal memory violations, their unpredictable effects, and how unique ownership can prevent the illustrated use-after-free while still requiring checks for empty pointers.
- Temporal memory safety violations: Distinguish temporal violations from spatial violations and explain why accessing a freed object is a temporal violation.
Why it matters: An address can appear valid even though the object it once held is no longer alive. - Use-after-free undefined behavior: Explain what can happen when the freed integer is dereferenced and what the differing results and warnings show.
Why it matters: An apparently correct output or a missing warning does not make a use-after-free safe. - Unique pointer lifetime ownership: Describe how the unique smart pointer prevents the illustrated use-after-free, and explain why its dereferences are not always safe.
Why it matters: Ownership avoids the example's manual lifetime error, but you must still ensure the pointer refers to a live object before dereferencing it.
Key terms: temporal memory safety, spatial violations, use after free, undefined behavior, optimization, std::make_unique, unique_ptr, ownership, use-after-free
2.4.3 Both dimensions together
This section explains why memory accesses need both spatial and temporal safety and illustrates the two checks in a buffer access.
- Combined memory safety requirements: Explain why a memory access must satisfy both spatial and temporal safety, and what happens if either requirement fails.
Why it matters: Checking only where or only when an access occurs cannot establish that the access is safe. - SensorBuffer paired checks: Trace how the SensorBuffer example checks lifetime and bounds before accessing an element, and explain why neither check alone is sufficient.
Why it matters: The example shows how two complementary checks prevent different invalid accesses.
Key terms: spatial violations, temporal violations, undefined behavior, temporal check, spatial check, std::optional<int>, SensorBuffer
2.5 The two categories of impacts
This section explains the reliability and security impacts of memory safety violations and their relevance to certification and remediation.
- Reliability and certification impacts: Explain how memory safety violations affect reliability and stability, and why unpredictable behavior blocks safety-critical certification.
Why it matters: These failures can prevent a safety-critical system from being certified. - Exploitable security vulnerabilities: Distinguish security vulnerabilities from reliability failures and explain how their impacts can overlap.
Why it matters: A defect that disrupts correct behavior may also give an attacker a way to take control. - Impact classification and standards: Explain how impact categories help guide remediation and coding standard selection, using MISRA C++ and CERT C++ as examples.
Why it matters: Classifying impacts helps you decide what to fix and which guidance fits your domain.
Key terms: reliability and stability failures, predictable behavior, certification, security vulnerabilities, attack vector, MISRA C++, CERT C++, remediation, coding standard
2.6 Toward compiler-enforced memory safety
This section explains proposed C++ safety profiles, how they would enforce guarantees, and their current state of development.
- Profile guarantees and process: Explain what a safety profile guarantees and how its approach differs from process-based defense in depth.
Why it matters: This distinction shows why profiles aim to make safety less dependent on consistently following a process. - Superset and subset mechanism: Describe the two halves of subsetting a superset of ISO C++ and how they work together to support a profile's guarantees.
Why it matters: The two halves explain how profiles provide usable checked alternatives while restricting operations that could break a guarantee. - Profile controls and compatibility: Describe how the proposed framework controls profile checks and how profiled code interacts with other C++ code.
Why it matters: These controls allow explicit exceptions and interoperability without making profiled code a separate language. - Profile development status: Describe the maturity of profiles and their availability in certified toolchains.
Why it matters: The proposed model should not be mistaken for a safety capability already available in certified toolchains. - Existing C++26 safety changes: State the C++26 safety changes cited as existing alongside the proposed profile work.
Why it matters: These existing changes distinguish current C++26 safety developments from the still-proposed profile framework.
Key terms: profile, guaranteed properties, defense-in-depth, compiler-enforced model, subsetting a superset, static analysis, hardened vector, span, pointer arithmetic, unchecked casts
2.7 Summary
Concepts explained in this chapter
- spatial memory safety violationSpatial memory safety is the property that memory accesses remain within the valid boundaries of the objects they access.
- style guideA set of rules specifying what software source code may contain and what it must not do.
- use-after-free errorUse-after-free is an error in which a program accesses memory after it has been deallocated.
- memory safetyThe property that a program's memory operations do not cause errors such as out-of-bounds access or corruption.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
