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.
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.
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.

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

Insights:

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

Interpretation:
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.
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).
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.
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
Insight: Initialization rules are well learned even by Sanitizr, reliably enforced one-time initialization (Rule 9.4) while occasionally under-correcting aggregate initializers.
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
Insight: H2LooP Code Sanitizr exhibited balanced correction under strong typing constraints, closely approximating Gemini's ~70% fix rate while avoiding aggressive code rewrites.
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
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).
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
Insight: Stable performance from all models in this rule.
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
Insight: Sanitizr aligned with Gemini Pro on control blocks.
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
Insight: Pointer-array handling was a strength for H2LooP, achieving ~80–100% average fix rates across all subrules, comparable to expert precision.
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
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.
Across rule families, H2LooP Code-Sanitizr (Beta) maintained consistent rule awareness, scoring:
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.
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:
int, missing definition.pDataParams, pValue.Flca_CUSTOM_TIMING_SUPPORT.#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):
pDataParams and pValue.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):
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:
This) in comment block.status may be uninitialized.|| expression (unsigned operand misuse).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):
This) in comment block.status may be uninitialized.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):
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:
#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):
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.)
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.
if–else coverage without altering logic.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: