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 Coverity 7.0.3.3.
There is no problem with your code. It uses array indexing as required. Your static analyser is broken.