Skip to content

[MISRA-CERT-19] printf/fprintf in generated code (MISRA Rule 21.6) #281

Closed

Description

@godofecht

Description

Generated C uses printf for println and fprintf(stderr, ...) for bounds-check error messages. MISRA C restricts use of stdio I/O functions.

src/flow/c_generator.py:

  • printf is in the stdlib_functions set (line 645).
  • Bounds checks emit fprintf(stderr, ...) (lines 3516, 3536).
  • println lowers to printf("%d\n", ...) etc.

Standards

  • MISRA C:2024 Rule 21.6 (Required): The standard library input/output functions shall not be used.
  • MISRA C:2024 Rule 21.13 (Advisory): The fprintf and printf functions should not be used.

Fix

  1. In --profile safety, println should route through a configurable logging channel, not raw printf.
  2. Bounds-check error messages should call flow_fault_handler(...) instead of fprintf(stderr, ...) + abort().
  3. Allow printf in default profile but document the deviation.
  4. Provide a flow_log(level, msg) runtime function as the safety-profile replacement.

Audit ID: MISRA-CERT-19

Severity: Medium | Category: C generator - I/O safety

Activity

  1. added
    enhancement
    MISRA
    CERT
    on Aug 9, 2026
  2. added 2 commits that reference this issue on Aug 10, 2026
  3. godofecht commented on Aug 10, 2026

    @godofecht
    ContributorAuthor

    Fixed in PR #404: println now routes through FLOW_LOG and FLOW_LOG_EMPTY macros instead of calling printf directly. Safety-critical builds override with -DFLOW_LOG(fmt, ...)=... to use a certified I/O abstraction. FLOW_DIAG already exists for diagnostic messages.

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

    CERTMISRAcompilerenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions