Contenido principal

hisl_0067: Protect against divide-by-zero calculations

R2026b

Protect the divisor from going to zero in divide operations to improve robustness of generated code

Usage: High-Integrity System Modeling

Guideline ID: hisl_0067

Rules

hisl_0067: Protect against divide-by-zero calculations

To support robustness of generated code, when performing divide operations, protect the divisor from going to zero.

Rationale

Improve code compliance of generated code.

Verification

Check for divide-by-zero calculations (Simulink Check)

Example — Correct

Graphical function to model divide-by-zero check.

Correct example of modeling to prevent divide-by-zero.

Example — Incorrect

Division operation can result in a divide-by-zero scenario.

Divide-by-zero exists in model example.

Tips

  • To prove that division-by-zero is not possible, perform a static analysis of the model.

  • If division-by-zero is possible, implement one of the following. Using more than one option can result in redundant protection operations:

  • Using CRLs or clearing configuration parameter Remove code that protects against integer division arithmetic exceptions (Embedded Coder) protects division operations against divide-by-zero operations. However, this action does introduce additional computational and memory overhead, as well as the potential to introduce unreachable code.

Industry Standards

  • IEC 61508-3, Table A.3 (3) 'Language subset'

    IEC 61508-3, Table A.4 (3) 'Defensive programming'

  • IEC 62304, 5.5.3 - Software Unit acceptance criteria

  • ISO 26262-6, Table 1(b) 'Use of language subsets'

    ISO 26262-6, Table 1(d) 'Use of defensive implementation techniques'

  • EN 50128, Table A.4 (11) 'Language Subset'

    EN 50128, Table A.3 (1) 'Defensive Programming'

  • EN 50657, Table A.4 (11) 'Language Subset'

    EN 50657, Table A.3 (1) 'Defensive Programming'

  • EN 50716, Table A.3 (1) 'Defensive Programming'

  • DO-331, Section MB.6.3.2.g 'Algorithms are accurate'

  • MISRA C:2012, Dir 4.1

  • MISRA C:2023, Dir 4.1

Version History

Introduced in R2021a

expand all