misra

MISRA-C:2012 warning of Rule 10.8 “being cast to a wider type”

不羁的心 提交于 2021-01-27 20:30:44
问题 I got a MISRA-C warning of Rule 10.8: A composite expression of 'essentially unsigned' type (unsigned char) is being cast to a wider unsigned type, 'unsigned short'. This warning was detected with the following code. void Fucntion(unsigned char isSwitchOn) { unsigned short switchMask = 0U; switchMask |= (unsigned short)(isSwitchOn & 1U) << 1; Why was a warning detected? Also, does this code cause problems? I think that the expression (isSwitchOn & 1U) is converted to an int type and

conversion between a pointer to function and another type [MISRA 2012 Rule 11.1, required] | pclint 9074

走远了吗. 提交于 2021-01-27 19:20:45
问题 I am using an array of function pointers as below to avoid a switch statement in the code. void E_func1(void); void E_func2(void); void E_func3(void); void (*pfGetVal[3])() = { E_func1, E_func2, E_func3 }; But while running misra (pclint), I am getting the error below: conversion between a pointer to function and another type [MISRA 2012 Rule 11.1, required] Do I need to use typedef ? I tried as below but didn't work. void (*pfGetVal[3])(); pfGetVal[0] = E_func1; pfGetVal[1] = E_func2;

How standard is the {0} initializer in C89?

喜欢而已 提交于 2020-08-22 03:00:21
问题 In my current project, which uses the MISRA 2004 standard, we use three GCC compilers, versions 3.2.3, 4.4.2 and 5.4.0. We run build checks with the pedantic switch and c89 standard and a load of other restrictions. One of the restrictions is that all data must be initialised at declaration. I have a problem in that on GCC 3.2.3, the universal zero initialiser {0} only compiles for arrays of the basic unitary types. If I have an array of structs, then I get a missing braces warning and the

MISRA:Cast between a pointer to volatile object and an integral type?

不羁岁月 提交于 2020-06-29 09:01:31
问题 I have following code section: ----------header--------------------- typedef volatile struct REG_Base{ a; b; }REG_t #define address (0xFFF45556) ------------------------------------ --------Source----------------------- LOCAL REG_t *pToREG; pToREG= (REG_t *) address; ------------------------------------- I got on the last line the MISRA message " Cast between a pointer to volatile object and an integral type ". Any idea how to avoid this message? Thx! 回答1: MISRA has an advisory rule which

MISRA C-2012 Rule 11.3 violation while trying to do a typecast from char to int pointer

跟風遠走 提交于 2020-05-30 07:53:23
问题 I am trying to get rid of Rule 11.3 from my code. Sample code: static int32_t do_test(const char *cp) { const char *c = cp; const int32_t *x; x = (const int32_t *)cp; return *x; } I want the value of *c and *x to be same. Even-though the code is compiling and giving the correct value, "x = (int32_t *)cp;" causing violation of 11.3 and 11.8 Rule 11.3 violation: An object with pointer type shall not be converted to a pointer to a different object type. I have tried with void pointer, but the

Is it legal write to a byte array in a union and read from an int to convert values in MISRA C?

跟風遠走 提交于 2020-04-13 08:05:11
问题 I guess this must have been asked before, but I could not get a specific yes/no answer. I have this code snippet : union integer_to_byte { signed int IntPart; unsigned char BytePart[2]; }; typedef union integer_to_byte I2B; main() { I2B u16VarNo; while(1) { // some code.... u16VarNo.BytePart[1]= P1; // some more code .... u16VarNo.BytePart[0]= P2; // still more code ... if(u16VarNo.IntPart != 0xFFFF) { } } } Is this a legal way to use Unions in C ? From what I read; only the last assigned

MISRA 2012 violation - Type mismatch (Rules 10.1, 10.4)

岁酱吖の 提交于 2020-03-21 18:59:49
问题 I'm facing MISRA C 2012 violation that I can't understand. Following is the code: #define I2C_CCRH_FS ((uint8_t)0x80) #define I2C_CCRH_DUTY ((uint8_t)0x40) #define I2C_CCRH_CCR ((uint8_t)0x0F) typedef struct I2C_struct { volatile uint8_t CR1; volatile uint8_t CR2; volatile uint8_t CCRL; volatile uint8_t CCRH; } I2C_TypeDef; #define I2C_BaseAddress 0x5210 #define I2C ((I2C_TypeDef *) I2C_BaseAddress) I2C->CCRH &= ~(uint8_t)((I2C_CCRH_FS | I2C_CCRH_DUTY) | I2C_CCRH_CCR); In the previous code,

Do BLAS and LAPACK libraries comply with MISRA standard?

血红的双手。 提交于 2020-01-16 08:35:55
问题 I guess the answer is no . However, I was wondering if someone has some insight into this topic. Do BLAS and LAPACK libraries comply with MISRA standards? The MISRA standards (MISRA C:1998, MISRA C:2004, MISRA C:2012) are extremly demanding, and I believe that BLAS and LAPACK libraries do not comply with it. Hence, I should not use such libraries if my software project demands MISRA compliance. Any insight into this question would be extremly appreciated :) 回答1: Unless the library is actively

MISRA C:2004, error with bit shifting

我怕爱的太早我们不能终老 提交于 2020-01-11 03:14:29
问题 I'm using IAR Workbench compiler with MISRA C:2004 checking on. The fragment is: #define UNS_32 unsigned int UNS_32 arg = 3U; UNS_32 converted_arg = (UNS_32) arg; /* Error line --> */ UNS_32 irq_source = (UNS_32)(1U << converted_arg); The MISRA error is: Error[Pm136]: illegal explicit conversion from underlying MISRA type "unsigned char" to "unsigned int" (MISRA C 2004 rule 10.3) I don't see any unsigned char in any of the code above. The discussion at Why did Misra throw an error here?