misra

MISRA C++-2008 Rule 5-0-15 - Array indexing shall be the only form of pointer arithmetic

依然范特西╮ 提交于 2019-12-06 15:54:07
问题 I need someone who has more experience with MISRA to help me to solve this. I have the following code: byte* buf = new(std::nothrow) byte[bufferSize]; ..... for (uint32_t i = 0; i < bufferSize; i+=4) { .............. { buf[ i+0 ] = b; buf[ i+1 ] = g; buf[ i+2 ] = r; (1) Event misra_violation: [Required] MISRA C++-2008 Rule 5-0-15 violation: Array indexing shall be the only form of pointer arithmetic. buf[ i+3 ] = a; } MISRA Rule 5-0-15 doesn't allow also ptr++ or ptr--. What should be the

Pointer to Array of Bytes

a 夏天 提交于 2019-12-06 13:47:27
I'm having some trouble with a pointer declaration that one of my co-workers wants to use because of Misra C requirements. Misra (Safety Critical guideline) won't let us mere Programmers use pointers, but will let us operate on arrays bytes. He intends to procur a pointer to an array of bytes (so we don't pass the actual array on the stack.) // This is how I would normally do it // void Foo(uint8_t* pu8Buffer, uint16_t u16Len) { } // This is how he has done it // void Foo(uint8_t (*pu8Buffer)[], uint16_t u16Len) { } The calling function looks something like; void Bar(void) { uint8_t u8Payload

Does MISRA C 2012 say not to use bool

孤者浪人 提交于 2019-12-06 02:49:28
问题 I am in the early stages of framing stuff out on a new project. I defined a function with a return type of "bool" I got this output from PC-Lint Including file sockets.h (hdr) bool sock_close(uint8_t socket_id); ^ "LINT: sockets.h (52, 1) Note 970: Use of modifier or type '_Bool' outside of a typedef [MISRA 2012 Directive 4.6, advisory]" I went ahead and defined this in another header to shut lint up: typedef bool bool_t; Then I started wondering why I had to do that and why it changed

MISRA C++ rule 5-0-3 false positive warning

亡梦爱人 提交于 2019-12-05 19:07:17
My static analyzer is throwing the following warning: MCPP Rule 5-0-3: This complex expression is implicitly converted to a different essential type for the following code: void func(const uint32_t arg) { //32U has underlying type uint8_t const uint32_t u32a = arg % 32U; //warning issued in this line const uint32_t u32b = (arg % static_cast<uint32_t>(32U)); //same warning issued in this line const uint32_t u32c = static_cast<uint32_t>(arg % 32U); //compliant } According to MISRA underlying type conversion rules: Otherwise, if both operands have integral type, the underlying type of the

Am I allowed to choose to disable these two MISRA rules: one statement per function and mandatory function prototypes?

浪子不回头ぞ 提交于 2019-12-05 12:42:52
Our company are now ISO-13485 (Medical devices) and wants to use MISRAC2012. I read the standard, but I cannot figure out whether or not I am allowed to disable some rules if I think it could improve both stability and readability. Two examples: MISRA only allows 1 return statement per function. This often lead to nested conditional structures that look like Christmas tree. I really don't think this rule increase safeness because it makes the code less readable and more error prone. MISRA only accept functions that have a prototype, even for static ones. This allows the programmer to place his

Why “continue” is considered as a C violation in MISRA C:2004?

ぐ巨炮叔叔 提交于 2019-12-05 00:52:59
MISRA 14.5 says continue statement must not be used. Can anyone explain the reason? Thank you. It is because of the ancient debate about goto , unconditional branching and spaghetti code, that has been going on for 40 years or so. goto , continue , break and multiple return statements are all considered more or less equally bad. The consensus of the world's programming community has roughly ended up something like: we recognize that you can use these features of the language without writing spaghetti code if you know what you are doing. But we still discourage them because there is a large

When should I use UINT32_C(), INT32_C(),… macros in C?

自作多情 提交于 2019-12-04 22:30:30
I switched to fixed-length integer types in my projects mainly because they help me think about integer sizes more clearly when using them. Including them via #include <inttypes.h> also includes a bunch of other macros like the printing macros PRIu32 , PRIu64 ,... To assign a constant value to a fixed length variable I can use macros like UINT32_C() and INT32_C() . I started using them whenever I assigned a constant value. This leads to code similar to this: uint64_t i; for (i = UINT64_C(0); i < UINT64_C(10); i++) { ... } Now I saw several examples which did not care about that. One is the

MISRA C++-2008 Rule 5-0-15 - Array indexing shall be the only form of pointer arithmetic

心不动则不痛 提交于 2019-12-04 21:03:28
I need someone who has more experience with MISRA to help me to solve this. I have the following code: byte* buf = new(std::nothrow) byte[bufferSize]; ..... for (uint32_t i = 0; i < bufferSize; i+=4) { .............. { buf[ i+0 ] = b; buf[ i+1 ] = g; buf[ i+2 ] = r; (1) Event misra_violation: [Required] MISRA C++-2008 Rule 5-0-15 violation: Array indexing shall be the only form of pointer arithmetic. buf[ i+3 ] = a; } MISRA Rule 5-0-15 doesn't allow also ptr++ or ptr--. What should be the approach here to increment/decrement and assign values using pointers created by new? My MISRA checker is

What is the difference between Integral Promotion and Balancing in C?

别说谁变了你拦得住时间么 提交于 2019-12-04 06:51:38
问题 What is the difference between integral promotion and balancing. Can we sum up both the rules by saying that any type is converted to atleast int or unsigned int type before performing any operation(except logical operators &&, ||, !) and to a greater type if any of the operand is of type greater than int ? 回答1: There are two different things in the standard but none is called balancing: If an int can represent all values of the original type (as restricted by the width, for a bit-field), the

Why did my tool throw a MISRA error here?

社会主义新天地 提交于 2019-12-04 03:38:46
问题 What can I do to avoid MISRA giving this error for the code below? I tried casting with (unit16_t). But then it didn't allow an explicit conversion. Illegal implicit conversion from underlying MISRA type "unsigned char" to "unsigned int" in complex expression (MISRA C 2004 rule 10.1) uint8_t rate = 3U; uint8_t percentage = 130U; uint16_t basic_units = rate * percentage; 回答1: The problem is that both rate and percentage are silently promoted by the integer promotions to type "int". The