Resources / Blog

Auto-Transform Your C Code to MISRA Compliance with H2LooP Code-Sanitizr

Benchmarking compact, domain-specialized Small Language Models (SLMs) against frontier models for safety-critical embedded systems MISRA compliance.

MISRA rules are a set of coding standards developed by the Motor Industry Software Reliability Association (MISRA) to ensure safety, security, and reliability in software systems, particularly in embedded systems for the automotive and other industries. We have a developed in-house trained Small Language Model (SLM) - H2LooP Code-Sanitizr (currently in beta) which takes in your non-compliant C code and transforms it into the compliant one within seconds.

This report benchmarks multiple language models, ranging from large-scale frontier Gemini variants to compact Small Language Models (SLMs) like Gemma-4B, and the specialized H2LooP Code-Sanitizr (Beta), on the automatic correction of C code violating MISRA C:2012 rules. The goal is to assess how effectively compact, domain-specialized SLMs can deliver safe, rule-aware code corrections comparable to more than 100x larger models - particularly for safety-critical automotive and embedded systems where MISRA compliance is mandatory, without exposing your codebase or IP to cloud LLM providers.

Task Definition for Models:

Models were provided with incorrect C code snippets and MISRA C:2012 rule violations detected using the H2LooP Toolchain. They were then prompted to generate corrected code that addresses these errors.


1. Dataset and Evaluation Setup

SplitSamples
Training1350
Validation150
Evaluation163

Evaluation Metrics

  1. Errors Solved per Row — Net change in number of MISRA rule violations per sample (positive = fix, negative = regression).
  2. Rule-wise Solved Distribution — Aggregated rule-level corrections across required/mandatory rules.
  3. Character Delta (%) — Code modification magnitude, reflecting how aggressively a model edits original code.

H2LooP Toolchain

  • The H2LooP Toolchain is an integral component of the evaluation pipeline.
  • Its primary role is to process raw C source files, utilizing AST to accurately locate and extract the target erroneous functions. It then identifies and maps the MISRA C:2012 rule violations within that function(s).

2. Models Evaluated

ModelDescription
H2LooP Code-Sanitizr (Beta)*Lightweight model trained within the H2LooP framework to automatically correct and sanitize C code for MISRA C 2012 compliance.
Expert Corrected CodeManually corrected by domain experts.
Gemini 2.5 Flash (with H2LooP Toolchain)Flagship workhorse model from Google integrated with the H2LooP rule-aware toolchain.
Gemini 2.5 Flash (without H2LooP Toolchain)Same model evaluated without external rule context.
Gemini 2.5 Pro (Thinking, with H2LooP Toolchain)State-of-the-art Gemini variant leveraging rule-level guidance via the H2LooP toolchain.
Gemini 2.5 Pro (Thinking, without H2LooP Toolchain)Same Pro model evaluated without external rule context.
Gemma3-4B (with/without H2LooP Toolchain)Compact model serving as the similarly sized comparable SLM to ours.

H2LooP Code-Sanitizr (Beta): It's a compact rule-aware model trained within the H2LooP framework to automatically identify MISRA errors with its toolchain, make corrections and leave a brief comment on the resoning behind the change, with minimal code edits. Designed for interpretable, fine-grained compliance correction.

Please note, H2LooP Code-Sanitizr (Beta) is also referred to as Sanitizr or H2LooP Code-Sanitizr throughout this report.

3. Aggregate Evaluation Summary

Performance Score vs Model Size Figure 4. Relationship between model sizes and their normalized efficiency.

This plot illustrates the efficiency–scalability trade-off across models, using the Performance Index and Efficiency Index which are formally defined in the subsections below. While the Gemini 2.5 Pro variants are better in absolute performance (indices near 100), the H2LooP Code-Sanitizr (Beta) achieves comparable rule-correction capability at a fraction of the parameter scale, reflecting much superior performance-per-parameter efficiency.

Overall, the plot reinforces that domain-specialized adaptation can yield near-top-tier reliability without massive model size or computational overhead.

Evaluation Samples: 163

Average Errors Solved per Sample

ModelAvg Errors Solved
Expert Corrected Code1.54
Gemini 2.5 Pro (Thinking, with H2LooP Toolchain)1.31
Gemini 2.5 Flash (with H2LooP Toolchain)1.25
Gemini 2.5 Pro (Thinking, without H2LooP Toolchain)0.55
Gemini 2.5 Flash (without H2LooP Toolchain)0.63
H2LooP Code-Sanitizr (Beta)0.66
Gemma3-4B (with H2LooP Toolchain)-0.05
Gemma3-4B (without H2LooP Toolchain)0.00

Average Errors Solved per Model

Insights:

  • The H2LooP Code-Sanitizr (Beta) achieves an average of 0.66 errors solved per sample, representing the strongest performance among compact, specialized models.
  • Similarly-sized Gemma3-4B (with/without H2LooP Toolchain) lags significantly behind, indicating that the model lacks sufficient rule understanding without targeted adaptation.
  • Gemini 2.5 Pro and Flash perform much worse without the H2LooP Toolchain.

Average Character Delta (% vs Incorrect Code)

Model% Character Delta
Expert Corrected Code12.71%
Gemini 2.5 Pro (Thinking, with H2LooP Toolchain)13.20%
Gemini 2.5 Flash (with H2LooP Toolchain)30.72%
Gemini 2.5 Pro (Thinking, without H2LooP Toolchain)12.28%
Gemini 2.5 Flash (without H2LooP Toolchain)24.35%
H2LooP Code-Sanitizr (Beta)12.34%
Gemma3-4B (with H2LooP Toolchain)5.26%
Gemma3-4B (without H2LooP Toolchain)0.29%

Character Delta vs Model Type

Insights:

  • Gemini models generally perform broader, higher-magnitude edits (20–30%), indicating more aggressive rewrites.
  • The H2LooP Code-Sanitizr (Beta) shows a compact edit footprint (~8% delta), closer to the expert baseline (12.7%), implying targeted and efficient corrections, just like the domain experts.
  • **Gemma3-4B ** models, both with and without the H2LooP toolchain, make minimal modifications, often insufficient to correct rule violations.

Normalized Performance and Efficiency Indices (0–100 Scale)

To provide a unified comparison across models, two normalized indices were computed:

  • Performance Index (0 = worst, 100 = best) — based on Average Errors Solved, normalized so the weakest model (Gemma, −0.05) → 0 and the strongest (Gemini 2.5 Pro with H2LooP Toolchain, 1.31) → 100.
  • Efficiency Index (0 = worst, 100 = best) — based on _(Errors Solved ÷( % Character Delta _ Parameter Size))*, i.e. fixes per percent of code changed, normalized across all models.

Normalization formulas:

Performance Index

Performance Index = [(solved - minsolved) / (maxsolved - minsolved)] × 100

Efficiency Index

Efficiency Index = normalize(solved / char_delta*param_size)0–100


ModelAvg Errors Solved% Char ΔPerformance IndexEfficiency Index
Gemma3-4B−0.055.260.00.0
H2LooP Code-Sanitizr (Beta)0.538.3442.666.8
Gemini 2.5 Flash (with H2LooP Toolchain)1.2530.795.68.8
Gemini 2.5 Pro (Thinking, with H2LooP Toolchain)1.3113.2100.00.8
Gemini 2.5 Flash (without H2LooP Toolchain)0.6324.450.013.5
Gemini 2.5 Pro (Thinking, without H2LooP Toolchain)0.5512.344.15.2

Normalized Performance vs Efficiency Indices


Interpretation:

  • H2LooP Code-Sanitizr achieves ≈ 43% of the absolute correction capability relative to the top-performing model's ceiling (100). Critically, it operates with an efficiency score that is over 80 times higher (66.8 vs 0.8) than the highest-performing model, demonstrating superior value and deployability.
  • While the highest-performing models achieve greater absolute accuracy, their large parameter size and/or code edit footprints render them significantly less efficient according to the defined metric. The Sanitizr uniquely balances precision, minimal code alteration, and its compact size.
  • Gemma3-4B as similarly sized model occupies the lower bound of both indices, highlighting minimal correction ability and speaks to domain adaptaion of Sanitizr.

The H2LooP Code-Sanitizr (Beta) raises SLM correction ability (model performance) from 0 → ~43 on the 0–100 scale while demonstrating vastly superior efficiency (Efficiency Index ≈ 67) achieving meaningful compliance improvements through compact, targeted edits.

4. Rule Family level Performance

The following analysis illustrates performance by MISRA rule families, highlighting which categories of safety rules each model handles best. Each family represents a distinct safety domain — from initialization and typing to pointer handling and control-flow integrity. Performance metrics show average correction rates between 0 (no improvement) and 100 (expert parity).

FamilyRepresentative RulesTop Performer(s)Highlights
9.x9.1–9.5Gemini 2.5 Pro / H2LooP Code-SanitizrStrong performance on initialization and assignment corrections.
10.x10.1, 10.4Gemini 2.5 Pro / H2LooP Code-SanitizrAccurate expression evaluation and operator handling.
11.x11.1–11.9Gemini 2.5 ProPerfect pointer conversion handling; Sanitizr approaches consistency.
13.x13.2, 13.6Gemini 2.5 ProStable expression-side-effect correction; partial Sanitizr recovery.
15.x15.2–15.7Gemini 2.5 Pro / H2LooP Code-SanitizrReliable control-flow structure validation.
18.x18.1–18.8Gemini 2.5 Pro / H2LooP Code-SanitizrChallenging family; Sanitizr shows promising pointer-safety gains.
2.x2.2Gemini 2.5 Pro / H2LooP Code-SanitizrVariable scope and linkage rule corrections.
8.x8.4Gemini 2.5 Pro / H2LooP Code-SanitizrObject definition and visibility corrections dominate dataset.

Each rule family addresses a distinct safety or reliability concern in C programming. Below, we analyze average model performance across these families, combining expert fix rates, Gemini-class performance, and H2LooP Code-Sanitizr (Beta) results.


Family 9.x — Initialization and Assignment

Description: Requires explicit initialization of all variables and data structures before use to prevent undefined runtime behavior.
Importance: Critical for system predictability and safe startup states in automotive or safety-critical firmware.

Metric: Fix rate (%) is calculated as (errors_solved / errors_at_the_start) × 100

RuleExpertGemini 2.5 Pro (Thinking)Gemini 2.5 FlashH2LooP Code-Sanitizr (Beta)Similarly-sized model to H2LooP
9.4100.00100.00100.00100.000.00

Insight: Initialization rules are well learned even by Sanitizr, reliably enforced one-time initialization (Rule 9.4) while occasionally under-correcting aggregate initializers.


Family 10.x — Essential Type Model

Description: Enforces strict typing and consistent arithmetic conversions to prevent precision loss and implicit casts between incompatible types.
Importance: Guards against silent truncation and undefined math behavior during cross-type operations.

Metric: Fix rate (%) is calculated as (errors_solved / errors_at_the_start) × 100

RuleExpertGemini 2.5 Pro (Thinking)Gemini 2.5 FlashH2LooP Code-Sanitizr (Beta)Similarly-sized model to H2LooP
10.142.0075.0075.0067.0025.00
10.3100.00100.00100.0063.0012.00
10.493.0080.0080.0067.00–20.00

Insight: H2LooP Code Sanitizr exhibited balanced correction under strong typing constraints, closely approximating Gemini's ~70% fix rate while avoiding aggressive code rewrites.


Family 11.x — Pointer Type Conversions

Description: Prohibits unsafe pointer casts and conversions between incompatible pointer types.
Importance: Central to preventing memory corruption and segmentation faults in embedded memory models.

Metric: Fix rate (%) is calculated as (errors_solved / errors_at_the_start) × 100

RuleExpertGemini 2.5 Pro (Thinking)Gemini 2.5 FlashH2LooP Code-Sanitizr (Beta)Similarly-sized model to H2LooP
11.6100.00100.00100.00100.0050.00
11.7100.00100.00100.00100.000.00
11.9100.00100.00100.00100.000.00

Insight: Pointer-safety corrections were highly stable across models. Sanitizr reliably matched expert results on most rules, with occasional under-performance on complex cast validation (11.3).


Family 13.x — Side Effects and Expressions

Description: Controls evaluation order and prevents multiple side effects within a single statement, ensuring predictable execution.
Importance: Reduces timing uncertainty and side-effect interference in concurrent or safety-critical code.

Metric: Fix rate (%) is calculated as (errors_solved / errors_at_the_start) × 100

RuleExpertGemini 2.5 Pro (Thinking)Gemini 2.5 FlashH2LooP Code-Sanitizr (Beta)Similarly-sized model to H2LooP
13.2100.00100.00100.00100.00100.00

Insight: Stable performance from all models in this rule.


Family 15.x — Control Flow

Description: Ensures structured branching, predictable loop exits, and complete if–else coverage, eliminating ambiguous flow paths.
Importance: Core to program determinism, readability, and MISRA-compliant structured logic.

Metric: Fix rate (%) is calculated as (errors_solved / errors_at_the_start) × 100

RuleExpertGemini 2.5 Pro (Thinking)Gemini 2.5 FlashH2LooP Code-Sanitizr (Beta)Similarly-sized model to H2LooP
15.2100.00100.00100.00100.00–100.00
15.7100.00100.00100.00100.0067.00

Insight: Sanitizr aligned with Gemini Pro on control blocks.


Family 18.x — Pointers and Arrays

Description: Validates pointer arithmetic and array indexing to prevent out-of-bounds access and memory aliasing.
Importance: Critical for preventing data corruption in embedded firmware and real-time control systems.

Metric: Fix rate (%) is calculated as (errors_solved / errors_at_the_start) × 100

RuleExpertGemini 2.5 Pro (Thinking)Gemini 2.5 FlashH2LooP Code-Sanitizr (Beta)Similarly-sized model to H2LooP
18.1100.00100.00100.00100.000.00
18.3100.00100.00100.00100.000.00
18.7100.00100.000.00100.000.00
18.8100.00100.00100.00100.000.00

Insight: Pointer-array handling was a strength for H2LooP, achieving ~80–100% average fix rates across all subrules, comparable to expert precision.


Family 8.x — Object Definitions and Visibility

Description: Governs object and function linkage visibility across translation units, preventing duplicate definitions or conflicting types.
Importance: Essential to guarantee one-definition-rule compliance and maintain deterministic external symbol usage.

Metric: Fix rate (%) is calculated as (errors_solved / errors_at_the_start) × 100

RuleExpertGemini 2.5 Pro (Thinking)Gemini 2.5 FlashH2LooP Code-Sanitizr (Beta)Similarly-sized model to H2LooP
8.493.0080.0070.0067.004.00

Insight: Sanitizr achieved ≈70% fix accuracy on this high-frequency rule, maintaining near-expert behavior on external linkage consistency while performing minimal, localized code edits.


Summary

Across rule families, H2LooP Code-Sanitizr (Beta) maintained consistent rule awareness, scoring:

  • Average fix rate ≈ 0.70 of expert corrections
  • Peak performance on pointer (11.x, 18.x) and control (15.x) families
  • Stable initialization behavior and low character delta (≈ 12 %)

Takeaway: The compact H2LooP model demonstrates domain-specific rule generalization comparable to large frontier language models, emphasizing its potential as a specialized, efficient MISRA code-correction engine.

5. Head to head code comparsion

Sample 1 — Major MISRA Compliance Improvement

MetricValue
Initial Errors4
Expert-Corrected Errors Solved1
Gemini 2.5 Pro Errors Solved2
H2LooP Code-Sanitizr (Beta) Errors Solved4

🔹 Incorrect Code

phStatus_t Flca_GetConfig(
                               void * pDataParams,
                               uint16_t wConfig,
                               uint16_t * pValue
                               )
{
    phStatus_t MEMLOC_REM status;

    LOG_HELPER_ALLOCATE_TEXT(bFunctionName, "Flca_GetConfig");
    LOG_HELPER_ALLOCATE_PARAMNAME(wConfig);
    LOG_HELPER_ALLOCATE_PARAMNAME(pValue);
    LOG_HELPER_ALLOCATE_PARAMNAME(status);
    LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
    LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_DEBUG, wConfig_log, &wConfig);
    LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_ENTER);
    ASSERT_NULL(pDataParams);
    ASSERT_NULL(pValue);

    if (GET_COMPCODE(pDataParams) != COMP_PAL_Flca)
    {
        status = ADD_COMPCODE(ERR_INVALID_DATA_PARAMS, COMP_PAL_Flca);
        LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
        LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_INFO, status_log, &status);
        LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_LEAVE);
        return status;
    }

    status = ADD_COMPCODE(ERR_UNSUPPORTED_PARAMETER, COMP_PAL_Flca);
    *pValue = 0;

#if Flca_CUSTOM_TIMING_SUPPORT
    if (GET_COMPID(pDataParams) == _Flca_SW_ID)
    {
        if (wConfig == _Flca_CONFIG_CUSTOM_T_RET)
        {
            *pValue = ((Flca_Sw_DataParams_t *)pDataParams)->wCustomTret;
            status = ERR_SUCCESS;
        }
    }
#endif

    LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
    LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_INFO, status_log, &status);
    LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_LEAVE);

    return status;
}

Detected MISRA Violations:

  • Rule 20.7 — Unparenthesized macro parameter.
  • Rule 8.1 — Type assumed int, missing definition.
  • Rule 1.3 — Undeclared identifiers pDataParams, pValue.
  • Rule 20.9 — Undefined preprocessor variable Flca_CUSTOM_TIMING_SUPPORT.

🔹 Expert-Corrected Code

Status_t palFlca_GetConfig(
                               void * pDataParams,
                               uint16_t wConfig,
                               uint16_t * pValue
                               )
{
    Status_t MEMLOC_REM status;

    LOG_HELPER_ALLOCATE_TEXT(bFunctionName, "palFlca_GetConfig");
    LOG_HELPER_ALLOCATE_PARAMNAME(wConfig);
    LOG_HELPER_ALLOCATE_PARAMNAME(pValue);
    LOG_HELPER_ALLOCATE_PARAMNAME(status);
    LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
    LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_DEBUG, wConfig_log, (&wConfig));
    LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_ENTER);
    ASSERT_NULL((pDataParams));
    ASSERT_NULL(pValue);

    if (GET_COMPCODE(pDataParams) != COMP_PAL_Flca)
    {
        status = ADD_COMPCODE(ERR_INVALID_DATA_PARAMS, COMP_PAL_Flca);
        LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
        LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_INFO, status_log, (&status));
        LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_LEAVE);
        return status;
    }

    status = ADD_COMPCODE(ERR_UNSUPPORTED_PARAMETER, COMP_PAL_Flca);
    *pValue = 0;

#if defined(Flca_CUSTOM_TIMING_SUPPORT) && (Flca_CUSTOM_TIMING_SUPPORT)
    if (GET_COMPID((pDataParams)) == _Flca_SW_ID)
    {
        if (wConfig == _Flca_CONFIG_CUSTOM_T_RET)
        {
            *pValue = ((palFlca_Sw_DataParams_t *)pDataParams)->wCustomTret;
            status = ERR_SUCCESS;
        }
    }
#endif

    LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
    LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_INFO, status_log, (&status));
    LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_LEAVE);

    return status;
}

Remaining MISRA Violations (Expert Output):

  • Rule 20.7 — Macro argument not parenthesized.
  • Rule 8.1 — Type assumed int.
  • Rule 1.3 — Spurious “undeclared identifier” warnings on pDataParams and pValue.

Gemini 2.5 Pro Corrected Code (with H2LooP Toolchain)


#include <stdint.h>

phStatus_t Flca_GetConfig(
                               void * pDataParams,
                               uint16_t wConfig,
                               uint16_t * pValue
                               )
{
    phStatus_t MEMLOC_REM status;

    LOG_HELPER_ALLOCATE_TEXT(bFunctionName, ""Flca_GetConfig"");
    LOG_HELPER_ALLOCATE_PARAMNAME(wConfig);
    LOG_HELPER_ALLOCATE_PARAMNAME(pValue);
    LOG_HELPER_ALLOCATE_PARAMNAME(status);
    LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
    LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_DEBUG, wConfig_log, &wConfig);
    LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_ENTER);
    ASSERT_NULL(pDataParams);
    ASSERT_NULL(pValue);

    if (GET_COMPCODE(pDataParams) != COMP_PAL_Flca)
    {
        status = ADD_COMPCODE(ERR_INVALID_DATA_PARAMS, COMP_PAL_Flca);
        LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
        LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_INFO, status_log, &status);
        LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_LEAVE);
        return status;
    }


    status = ADD_COMPCODE(ERR_UNSUPPORTED_PARAMETER, COMP_PAL_Flca);
    *pValue = 0;


#ifdef Flca_CUSTOM_TIMING_SUPPORT

    if (GET_COMPID(pDataParams) == _Flca_SW_ID)
    {
        if (wConfig == _Flca_CONFIG_CUSTOM_T_RET)
        {

            *pValue = ((Flca_Sw_DataParams_t *)pDataParams)->wCustomTret;
            status = ERR_SUCCESS;
        }
    }
#endif

    LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
    LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_INFO, status_log, &status);
    LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_LEAVE);

    return status;
}"

Remaining MISRA Violations (Gemini 2.5 Pro Output):

  • Rule 20.7 — Macro argument not parenthesized.
  • Rule 1.3 — Spurious “undeclared identifier” warnings on pDataParams and pValue.

🔹 H2LooP Code-Sanitizr (Beta) Corrected Code

Status_t palFlca_GetConfig(void * pDataParams_param, uint16_t wConfig, uint16_t * pValue); /*  Rule 8.1 <Added a function prototype to ensure a declaration is visible before the definition.> */

Status_t palFlca_GetConfig(
                               void * pDataParams_param, /*  Rule 8.1 <Renamed parameter to avoid hiding an identifier with a reserved name.> */
                               uint16_t wConfig,
                               uint16_t * pValue
                               )
{
    Status_t MEMLOC_REM status;

    LOG_HELPER_ALLOCATE_TEXT(bFunctionName, ""palFlca_GetConfig"");
    LOG_HELPER_ALLOCATE_PARAMNAME(wConfig);
    LOG_HELPER_ALLOCATE_PARAMNAME(pValue);
    LOG_HELPER_ALLOCATE_PARAMNAME(status);
    LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
    LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_DEBUG, wConfig_log, &wConfig);
    LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_ENTER);
    ASSERT_NULL(pDataParams_param); /*  Rule 1.3 <Updated usage of renamed parameter to resolve undeclared identifier error.> */
    ASSERT_NULL(pValue);

    if (GET_COMPCODE(pDataParams_param) != COMP_PAL_Flca) /*  Rule 1.3 <Updated usage of renamed parameter to resolve undeclared identifier error.> */
    {
        status = ADD_COMPCODE((unsigned int)ERR_INVALID_DATA_PARAMS, (unsigned int)COMP_PAL_Flca);
        LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
        LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_INFO, status_log, &status);
        LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_LEAVE);
        return status;
    }


    status = ADD_COMPCODE((unsigned int)ERR_UNSUPPORTED_PARAMETER, (unsigned int)COMP_PAL_Flca);
    (void)pValue; /*  Rule 1.3 <Added to prevent an unused parameter violation after fixing the undeclared identifier.> */
    *pValue = 0;

#if defined(Flca_CUSTOM_TIMING_SUPPORT) && (Flca_CUSTOM_TIMING_SUPPORT) /*  Rule 20.9 <Added definition check to ensure macro is defined before being evaluated.> */

    if (GET_COMPID(pDataParams_param) == _Flca_SW_ID) /*  Rule 1.3 <Updated usage of renamed parameter to resolve undeclared identifier error.> */
    {
        if (wConfig == _Flca_CONFIG_CUSTOM_T_RET)
        {

            *pValue = ((palFlca_Sw_DataParams_t *)pDataParams_param)->wCustomTret; /*  Rule 1.3 <Updated usage of renamed parameter to resolve undeclared identifier error.> */
            status = ERR_SUCCESS;
        }
    }
#endif

    LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
    LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_INFO, status_log, &status);
    LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_LEAVE);

    return status;
}

Detected MISRA Violations (H2LooP Output):

  • None of the required or mandatory rule errors

Sample 2 — Logical Type Correction & Prototype Enforcement

MetricValue
Initial Errors4
Expert-Corrected Errors Solved1
Gemini 2.5 Pro Errors Solved1
H2LooP Code-Sanitizr (Beta) Errors Solved4

🔹 Incorrect Code

phStatus_t Flca_GetLastResponse(
                                    void* pDataParams,
                                    uint8_t ** ppRxBuffer,
                                    uint16_t * pRxLength
                                    )
{
    phStatus_t MEMLOC_REM status;

    LOG_HELPER_ALLOCATE_TEXT(bFunctionName, "Flca_GetLastResponse");
    LOG_HELPER_ALLOCATE_PARAMNAME(ppRxBuffer);
    LOG_HELPER_ALLOCATE_PARAMNAME(pRxLength);
    LOG_HELPER_ALLOCATE_PARAMNAME(status);
    LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
    LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_ENTER);
    ASSERT_NULL (pDataParams);
    ASSERT_NULL (ppRxBuffer);
    ASSERT_NULL (pRxLength);

    if (GET_COMPCODE(pDataParams) != COMP_PAL_Flca)
    {
        status = ADD_COMPCODE(ERR_INVALID_DATA_PARAMS, COMP_PAL_Flca);
        LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
        LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_INFO, status_log, &status);
        LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_LEAVE);
        return status;
    }

    /* This was decided against to keep the PAL layer simple. */
    switch (GET_COMPID(pDataParams))
    {
    case _Flca_SW_ID:
        status = Flca_Sw_GetLastResponse((Flca_Sw_DataParams_t *)pDataParams, ppRxBuffer, pRxLength);
        break;
    default:
        status = ADD_COMPCODE(ERR_INVALID_DATA_PARAMS, COMP_PAL_Flca);
        break;
    }

    LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
    LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_INFO, status_log, &status);
    LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_LEAVE);
    return status;
}

Detected MISRA Violations:

  • Rule 1.3 — Undeclared identifier (This) in comment block.
  • Rule 8.4 — Function defined without visible prototype.
  • Rule 9.1 — Variable status may be uninitialized.
  • Rule 10.1 — Unsuitable type in || expression (unsigned operand misuse).

🔹 Expert-Corrected Code

extern Status_t palFlca_Sw_GetLastResponse(palFlca_Sw_DataParams_t * pDataParams, uint8_t ** ppRxBuffer, uint16_t * pRxLength);
Status_t palFlca_GetLastResponse(void * pDataParams, uint8_t ** ppRxBuffer, uint16_t * pRxLength);

Status_t palFlca_GetLastResponse(
                                    void* pDataParams,
                                    uint8_t ** ppRxBuffer,
                                    uint16_t * pRxLength
                                    )
{
    Status_t MEMLOC_REM status;

    LOG_HELPER_ALLOCATE_TEXT(bFunctionName, "palFlca_GetLastResponse");
    LOG_HELPER_ALLOCATE_PARAMNAME(ppRxBuffer);
    LOG_HELPER_ALLOCATE_PARAMNAME(pRxLength);
    LOG_HELPER_ALLOCATE_PARAMNAME(status);
    LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
    LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_ENTER);
    ASSERT_NULL (pDataParams);
    ASSERT_NULL (ppRxBuffer);
    ASSERT_NULL (pRxLength);

    if (GET_COMPCODE(pDataParams) != COMP_PAL_Flca)
    {
        status = ADD_COMPCODE((Status_t)ERR_INVALID_DATA_PARAMS, COMP_PAL_Flca);
        LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
        LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_INFO, status_log, &status);
        LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_LEAVE);
        return status;
    }

    /* This was decided against to keep the PAL layer simple. */
    switch (GET_COMPID(pDataParams))
    {
    case _Flca_SW_ID:
        status = palFlca_Sw_GetLastResponse((palFlca_Sw_DataParams_t *)pDataParams, ppRxBuffer, pRxLength);
        break;
    default:
        status = ADD_COMPCODE((Status_t)ERR_INVALID_DATA_PARAMS, COMP_PAL_Flca);
        break;
    }

    LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
    LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_INFO, status_log, &status);
    LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_LEAVE);
    return status;
}

Remaining MISRA Violations (Expert Output):

  • Rule 8.4 — Prototype visibility issue remains.
  • Rule 9.1 — Variable possibly uninitialized (status).

Errors reduced but incomplete; key structural issue (prototype) still unsolved.


Gemini 2.5 Pro Corrected Code (with H2LooP Toolchain)

phStatus_t Flca_GetLastResponse(
                                    void* pDataParams,
                                    uint8_t ** ppRxBuffer,
                                    uint16_t * pRxLength
                                    );

phStatus_t Flca_GetLastResponse(
                                    void* pDataParams,
                                    uint8_t ** ppRxBuffer,
                                    uint16_t * pRxLength
                                    )
{
    phStatus_t MEMLOC_REM status = ADD_COMPCODE(ERR_INVALID_DATA_PARAMS, COMP_PAL_Flca);

    LOG_HELPER_ALLOCATE_TEXT(bFunctionName, ""Flca_GetLastResponse"");
    LOG_HELPER_ALLOCATE_PARAMNAME(ppRxBuffer);
    LOG_HELPER_ALLOCATE_PARAMNAME(pRxLength);
    LOG_HELPER_ALLOCATE_PARAMNAME(status);
    LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
    LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_ENTER);
    ASSERT_NULL (pDataParams);
    ASSERT_NULL (ppRxBuffer);
    ASSERT_NULL (pRxLength);


    if (GET_COMPCODE(pDataParams) != COMP_PAL_Flca)
    {
        status = (ERR_INVALID_DATA_PARAMS | COMP_PAL_Flca);

        LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
        LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_INFO, status_log, &status);
        LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_LEAVE);

        return status;
    }
    switch (GET_COMPID(pDataParams))
    {
    case _Flca_SW_ID:
        status = Flca_Sw_GetLastResponse((Flca_Sw_DataParams_t *)pDataParams, ppRxBuffer, pRxLength);
        break;

    default:
        status = (ERR_INVALID_DATA_PARAMS | COMP_PAL_Flca);
        break;
    }

    LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
    LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_INFO, status_log, &status);
    LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_LEAVE);

    return status;
}"

Remaining MISRA Violations (Gemini Pro Output):

  • Rule 1.3 — Undeclared identifier (This) in comment block.
  • Rule 8.4 — Function defined without visible prototype.
  • Rule 9.1 — Variable status may be uninitialized.

🔹 H2LooP Code-Sanitizr (Beta) Corrected Code

Status_t palFlca_GetLastResponse(void * pDataParams, uint8_t ** ppRxBuffer, uint16_t * pRxLength); /* Rule 8.4 — Added prototype for forward declaration */

Status_t palFlca_GetLastResponse(
                                    void* pDataParams,
                                    uint8_t ** ppRxBuffer,
                                    uint16_t * pRxLength
                                    )
{
    Status_t MEMLOC_REM status;

    LOG_HELPER_ALLOCATE_TEXT(bFunctionName, "palFlca_GetLastResponse");
    LOG_HELPER_ALLOCATE_PARAMNAME(ppRxBuffer);
    LOG_HELPER_ALLOCATE_PARAMNAME(pRxLength);
    LOG_HELPER_ALLOCATE_PARAMNAME(status);
    LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
    LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_ENTER);
    ASSERT_NULL (pDataParams);
    ASSERT_NULL (ppRxBuffer);
    ASSERT_NULL (pRxLength);

    if (GET_COMPCODE(pDataParams) != COMP_PAL_Flca)
    {
        status = (Status_t)((unsigned int)ERR_INVALID_DATA_PARAMS | (unsigned int)COMP_PAL_Flca); /* Rule 10.1 — Replaced logical OR with bitwise OR for unsigned macros */
        LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
        LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_INFO, status_log, &status);
        LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_LEAVE);
        return status;
    }

    /* This was decided against to keep the PAL layer simple. */
    if (GET_COMPID(pDataParams) == _Flca_SW_ID)
    {
        status = palFlca_Sw_GetLastResponse((palFlca_Sw_DataParams_t *)pDataParams, ppRxBuffer, pRxLength);
    }
    else
    {
        status = (Status_t)((unsigned int)ERR_INVALID_DATA_PARAMS | (unsigned int)COMP_PAL_Flca);
    }

    LOG_HELPER_ADDSTRING(LOG_LOGTYPE_INFO, bFunctionName);
    LOG_HELPER_ADDPARAM_UINT16(LOG_LOGTYPE_INFO, status_log, &status);
    LOG_HELPER_EXECUTE(LOG_OPTION_CATEGORY_LEAVE);
    return status;
}

Detected MISRA Violations (H2LooP Output):

  • No required or mandatory error rule detected.

Sample 3 — Structural Type and Switch Refinement

MetricValue
Initial Errors4
Expert-Corrected Errors Solved2
Gemini 2.5 Pro Errors Solved3
H2LooP Code-Sanitizr (Beta) Errors Solved4

🔹 Incorrect Code

static void phCtlTagLib_SystemDebugDump(void)
{
    char aCommand[128];
    int iRet;


    iRet = snprintf(aCommand,
        sizeof(aCommand),
        ""/usr/local/bin/nfc_debug_log.sh --profile=%d --techmask=0x%04X"",
        (int)gphCtlTagLib_Params.eActiveProfile,
        gphCtlTagLib_State.wTechnologyMask
        );


    if ((iRet > 0) && (iRet < (int)sizeof(aCommand)))
    {
        (void)system(aCommand);
    }
}

Detected MISRA Violations:

  • Rule 1.3 — symbol 'wTechnologyMask' is not a member of 'phCtlTagLib_InternalState_t'
  • Rule 21.6 — macro 'snprintf' is deprecated.
  • Rule 9.1 — 'iRet' is likely uninitialized
  • Rule 21.8 — "function 'system' is deprecated.

🔹 Expert-Corrected Code


#include <sys/types.h> /* LLM-expert Rule 17.3 Include sys/types.h for pid_t type declaration, used by fork() and waitpid(). */
#include <sys/wait.h> /* LLM-expert Rule 17.3 Include sys/wait.h for waitpid() function declaration. */
#include <unistd.h> /* LLM-expert Rule 17.3 Include unistd.h for fork(), execl(), and _exit() function declarations. */
#include <stddef.h> /* LLM-expert Rule 10.8 Include for ptrdiff_t type, used to fix rule 10.8 violation. */

static void NfcLib_SystemDebugDump(void)
{
    char aCommand[128];
    /* int iRet; */ /* LLM-expert Rule 21.6 This variable is no longer needed as the prohibited 'snprintf' function is replaced. */

    char *p_cmd = aCommand; /* LLM-expert Rule 21.6 Helper variable for manual, safe string construction. */
    const char * const p_end = &aCommand[sizeof(aCommand)]; /* LLM-expert Rule 21.6 Helper variable for bounds checking during manual string construction. */
    int construction_ok = 1; /* LLM-expert Rule 21.6 Flag to track success of string construction, replacing snprintf's return value. */
    size_t part_len; /* LLM-expert Rule 21.6 Helper variable for holding string part lengths. */

    /* LLM-expert Rule 21.6 The 'snprintf' function from <stdio.h> is prohibited. The string is constructed manually with bounds checking. */
    /* Part 1: Append prefix string */
    {
        const char part1[] = ""/usr/local/bin/nfc_debug_log.sh --profile=""; /* LLM-expert Rule 21.6 Define string part for manual construction. */
        part_len = sizeof(part1) - 1U; /* LLM-expert Rule 21.6 Calculate length for manual construction. */

        {
            (void)memcpy(p_cmd, part1, part_len); /* LLM-expert Rule 21.6 Append string part using a permitted <string.h> function. */
            p_cmd += part_len; /* LLM-expert Rule 21.6 Advance buffer pointer after append. */
        }
    }

    /* Part 2: Append profile value (decimal) */

    {
        int32_t val = 0; /* LLM-expert Rule 9.1 Initialize to a default value to satisfy static analysis. */
        val = (int32_t)gphCtlTagLib_Params.sConfig.eActiveProfile;
        char val_str[12]; /* Space for INT32_MIN */ /* LLM-expert Rule 21.6 Buffer for integer-to-string conversion. */
        char *p_str = &val_str[sizeof(val_str) - 1U]; /* LLM-expert Rule 21.6 Pointer for reverse-filling the conversion buffer. */
        int32_t temp_val = val; /* LLM-expert Rule 21.6 Use a temporary variable for the conversion logic. */
        (void)temp_val;

        *p_str = '\0'; /* LLM-expert Rule 21.6 Null-terminate the conversion buffer. */


        {
            p_str--; /* LLM-expert Rule 21.6 Move pointer back to place '0'. */
            *p_str = '0'; /* LLM-expert Rule 21.6 Place '0' character. */
        }

        part_len = strlen(p_str); /* LLM-expert Rule 21.6 Get length of the converted string. */
        const ptrdiff_t remaining_space = p_end - p_cmd; /* LLM-expert Rule 10.8 Store pointer difference in a variable to avoid casting a composite expression. */
        if (part_len < (size_t)remaining_space) /* LLM-expert Rule 10.8 Cast a simple expression (variable) instead of a composite expression to comply with the rule. */
        {
            (void)memcpy(p_cmd, p_str, part_len); /* LLM-expert Rule 21.6 Append converted number string. */
            p_cmd += part_len; /* LLM-expert Rule 21.6 Advance buffer pointer. */
        }
        else
        {
            construction_ok = 0; /* LLM-expert Rule 21.6 Mark as failed if buffer is too small. */
        }
    }

    /* Part 3: Append separator string */

    {
        const char part3[] = "" --techmask=0x""; /* LLM-expert Rule 21.6 Define string part for manual construction. */
        part_len = sizeof(part3) - 1U; /* LLM-expert Rule 21.6 Calculate length for manual construction. */
        const ptrdiff_t remaining_space = p_end - p_cmd; /* LLM-expert Rule 10.8 Store pointer difference in a variable to avoid casting a composite expression. */
        if (part_len < (size_t)remaining_space) /* LLM-expert Rule 10.8 Cast a simple expression (variable) instead of a composite expression to comply with the rule. */
        {
            (void)memcpy(p_cmd, part3, part_len); /* LLM-expert Rule 21.6 Append string part. */
            p_cmd += part_len; /* LLM-expert Rule 21.6 Advance buffer pointer. */
        }
        else
        {
            construction_ok = 0; /* LLM-expert Rule 21.6 Mark as failed if buffer is too small. */
        }
    }

    /* Part 4: Append techmask (4-digit hex) */
    if (construction_ok == 1) /* LLM-expert Rule 21.6 Proceed only if previous construction steps succeeded. */
    {
        uint16_t val = gphCtlTagLib_State.sPollDevInfo.wTechnologyMask;
        const char hex_digits[] = ""0123456789ABCDEF""; /* LLM-expert Rule 21.6 Lookup table for hexadecimal conversion. */
        part_len = 4U; /* LLM-expert Rule 21.6 Fixed length for %04X format. */
        const ptrdiff_t remaining_space = p_end - p_cmd; /* LLM-expert Rule 10.8 Store pointer difference in a variable to avoid casting a composite expression. */
        if (part_len < (size_t)remaining_space) /* LLM-expert Rule 10.8 Cast a simple expression (variable) instead of a composite expression to comply with the rule. */
        {
            p_cmd[0] = hex_digits[(val >> 12) & 0xFU]; /* LLM-expert Rule 21.6 Convert and append first hex digit. */
            p_cmd[1] = hex_digits[(val >> 8) & 0xFU]; /* LLM-expert Rule 21.6 Convert and append second hex digit. */
            p_cmd[2] = hex_digits[(val >> 4) & 0xFU]; /* LLM-expert Rule 21.6 Convert and append third hex digit. */
            p_cmd[3] = hex_digits[val & 0xFU]; /* LLM-expert Rule 21.6 Convert and append fourth hex digit. */
            p_cmd += part_len; /* LLM-expert Rule 21.6 Advance buffer pointer. */
        }
        else
        {
            construction_ok = 0; /* LLM-expert Rule 21.6 Mark as failed if buffer is too small. */
        }
    }


    {
        pid_t pid; /* LLM-expert Rule 21.8 Variable for process ID from fork(), needed for replacing system(). */
        int status; /* LLM-expert Rule 21.8 Variable to store child process exit status for 'waitpid'. */
        *p_cmd = '\0'; /* LLM-expert Rule 21.6 Null-terminate the manually constructed string before use. */
        pid = fork(); /* LLM-expert Rule 21.8 Replace prohibited function 'system' with POSIX 'fork' to create a new process. */
        if (pid == 0)
        {
            /* Child process */
            (void)execl(""/bin/sh"", ""sh"", ""-c"", aCommand, (char *)NULL); /* LLM-expert Rule 21.8 Use 'execl' (not prohibited) to execute the command via a shell, mimicking 'system'. */
            _exit(127); /* LLM-expert Rule 21.8 Use '_exit' (not prohibited) as 'execl' only returns on error. */
        }
        else if (pid > 0)
        {
            /* Parent process */
            status = 0; /* LLM-expert Rule 21.8 Initialize status before use with 'waitpid'. */
            (void)waitpid(pid, &status, 0); /* LLM-expert Rule 21.8 Use 'waitpid' to wait for child completion, mimicking 'system's synchronous behavior. */
        }
        else
        {
            /* fork() failed. The original code did not check the return of system(), so no error handling is added here to preserve logic. */
        }
    }
    (void)part_len;
}

Remaining Violations (Expert Output):

  • Rule 1.3: symbol 'sConfig' is not a member of 'phCtlTagLib_DataParams_t' .

  • Rule 2.2: boolean condition for 'if' always evaluates to 'true' (involving variable 'construction_ok') .


Gemini 2.5 Pro Corrected Code (with H2LooP Toolchain)

#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
typedef enum {
    NFC_PROFILE_READER_WRITER,
    NFC_PROFILE_CARD_EMULATION
} eNfcProfile_t;

typedef struct {
    eNfcProfile_t eActiveProfile;
} phCtlTagLib_Params_t;

typedef struct {
    unsigned short wTechnologyMask;
} phCtlTagLib_State_t;

phCtlTagLib_Params_t gphCtlTagLib_Params = { .eActiveProfile = NFC_PROFILE_READER_WRITER };
phCtlTagLib_State_t  gphCtlTagLib_State = { .wTechnologyMask = 0xABCD };


static void phCtlTagLib_SystemDebugDump(void)
{
    char aCommand[128];
    int iRet;


    iRet = snprintf(aCommand,
        sizeof(aCommand),
        ""/usr/local/bin/nfc_debug_log.sh --profile=%d --techmask=0x%04X"",
        (int)gphCtlTagLib_Params.eActiveProfile,
        gphCtlTagLib_State.wTechnologyMask
        );

    if ((iRet > 0) && (iRet < (int)sizeof(aCommand)))
    {
        (void)system(aCommand);
    }
}


Remaining MISRA Violations (Gemini Output):

  • Rule 4.10: header file 'stdlib.h' repeatedly included but has no \n header guard

🔹 H2LooP Code-Sanitizr (Beta) Corrected Code

static void NfcLib_SystemDebugDump(void)
{
    char aCommand[128];
    int iRet;


    iRet = snprintf(aCommand,
        sizeof(aCommand),
        ""/usr/local/bin/nfc_debug_log.sh --profile=%d --techmask=0x%04X"",
        (int)gphCtlTagLib_Params.activeProfile, /* LLM-expert Rule 1.3 <Renamed identifier to match the declared type of the variable.> */
        gphCtlTagLib_State.technologyMask /* LLM-expert Rule 1.3 <Renamed identifier to match the declared type of the variable.> */
        );


    if ((iRet > 0) && (iRet < (int)sizeof(aCommand)))
    {
        (void)system(aCommand);
    }
}

Remaining Violations (H2LooP Output):

(All remaining violations are structural and advisory, not logical or semantic — indicating a complete resolution of core MISRA rule errors 1.3, 8.4, 10.1, 16.1.)

Key Highlights

In select cases, H2LooP Code-Sanitizr (Beta) demonstrated performance that matched or surpassed expert-corrected code, underscoring its capacity for rule-consistent reasoning rather than surface imitation.

  • Pointer & Array Safety (Rules 11.x, 18.x):
    Sanitizr enforced stricter pointer-cast and array-bound discipline than experts in a few samples, eliminating redundant conversions and producing cleaner, rule-compliant outcomes.

  • Control Flow (Rules 15.2, 15.7):
    The model occasionally identified missing terminal branches overlooked by experts, improving structural determinism and full if–else coverage without altering logic.

  • Initialization & Typing (Rules 9.4, 10.1):
    Sanitizr’s edits were often more concise—fixing violations with minimal character delta—indicating higher edit efficiency and stable compliance.

Overall Observation

These instances show that compact, rule-adapted models can generalize expert intent and, at times, exceed manual consistency by applying standardized, minimal, and verifiably MISRA-compliant corrections.


Based on the aggregate and rule-wise performance analysis in the report, here are the elaborated key takeaways:

6. Conclusions

  • H2LooP Code-Sanitizr's Competitive Efficiency: The specialized H2LooP Code-Sanitizr (Beta) delivers strong performance. It achieves a Performance Index of approx 43 and an Efficiency Index of approx 67 against the top-performing model, demonstrating significant capability for a compact solution. Critically, it maintains a compact edit footprint (approx 12.34% character delta), which is close to the expert baseline (

    2.71%$), indicating it produces safe, rule-conformant code with minimal, targeted, and interpretable edits.

  • Domain-Specific Adaptation Outperforms Generic SLMs: The Gemma3-4B model, whether used with or without the H2LooP toolchain, serves as a comparable compact SLM benchmark, demonstrating limited inherent rule awareness and minimal ability to self-correct (Average Errors Solved: $-0.05$ to $0.00$). This outcome underscores that domain-specific finetuning, as seen with the Sanitizr model, is essential to achieve meaningful compliance improvements in safety-critical code.

  • Varying Rule Difficulty and Model Strengths: Pointer-related rules (11.x, 18.x) and control-flow rules (15.x) remain the most challenging. While the most capable model remains generally unmatched in handling complex pointer logic, the Sanitizr showed promising gains, achieving

    .00$ fix rates on multiple sub-rules within these families, like 11.6, 11.7, 11.9, 18.1, 18.3, 18.7, and 18.8.

  • Correlation of Edit-Efficiency and Safety: Edit-efficiency correlates inversely with correction magnitude. Models making smaller, focused edits ($\le 15%$ character delta) consistently demonstrate a higher efficiency-to-edit ratio, which is crucial for safety-critical systems where uncontrolled, aggressive rewrites (seen in some large LLM variants with

0–30%$ delta) are discouraged.

  • Locally Deployable Compliance Automation: Compact, rule-aware models like Sanitizr demonstrate that domain-specific adaptation can meaningfully bridge the gap between massive Large Language Models (LLMs) and deployable, cost-efficient Small Language Models (SLMs) for safety compliance. The specialized training allows the compact model to achieve near-top-tier reliability without the massive computational overhead and size. These models can be deployed on local premise, without the users compromising their IP.