Skip to content

[MISRA-CERT-01] Integer overflow not checked in generated C (MISRA Rule 12.1, CERT INT32-C) #263

Closed

Description

@godofecht

Description

The C generator emits raw arithmetic for +, -, * on integer types with no overflow check. Signed integer overflow is undefined behavior in C (C11 6.5p5).

Reproduction:

function main() -> i32 {
    let y: i32 = 2147483647 + 1
    return y
}

Generated C:

int32_t y = (2147483647 + 1);  // signed overflow, UB

src/flow/c_generator.py line 3137: return f"({left_expr} {c_operator} {right_expr})" emits the raw operation.

Standards

  • MISRA C:2024 Rule 12.1 (Required): Signed integer overflow shall not occur.
  • CERT C INT32-C: Ensure that integer operations do not result in an overflow.

Fix

Add a --checked-arith flag (or --profile safety) that emits overflow-checked arithmetic using __builtin_sadd_overflow / __builtin_smul_overflow / __builtin_ssub_overflow (Clang/GCC builtins) or a portable fallback. Abort or call a configurable handler on overflow.

Audit ID: MISRA-CERT-01

Severity: Critical | Category: C generator - arithmetic safety

Activity

  1. added
    enhancement
    MISRA
    CERT
    on Aug 9, 2026
  2. added a commit that references this issue on Aug 10, 2026
    79e67de
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CERTMISRAcompilerenhancementsecurity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions