MATLAB: Do I receive a red check or when using -allow-ptr​-arith-on-​struct option an orange in PolySpace Client for C/C++ 4.2 (R2008a)

Polyspace Client for C/C++Polyspace Code ProverPolyspace Code Prover Server

I am using PolySpace to analyze some autogenerated code which iterates a pointer over a struct as follows.
*(&StructVar.destValue) = *((&StructVar.destValue)+1);
For the testcase, the target was set to 8-bit in order to exclude an alignment problem.
I have also verified that calls are ANSI C compliant from the compliance documentation for C99-Standard ISO/IEC 9899:TC3, Page 115, Sentence 13 which states the following:
Within a structure object, the non-bit-field members and the units in which bit-fields reside have addresses that increase in the order in which they are declared. A pointer to a structure object, suitably converted, points to its initial member (or if that member is a bit-field, then to the unit in which it resides), and vice versa. There may be unnamed padding within a structure object, but not at its beginning.
However, on running the analysis, I receive the red check on this code with the following error:
Error : pointer is outside its bounds
On using the -allow-ptr-arit-on-struct option I receive an orange:
Warning : local variable may be non-initialized (type: int 8)
I expect a green check on this construct since it is ANSI-compliant.

Best Answer

Although the ANSI C compliance documentation states that:
[Fields inside a structure] have addresses that increase in the order in which they are declared.
It also states the following:
According to the ANSI C standard, pointer arithmetic is to be independent of the size of the object to which the pointer points.
However, in this particular case, the pointer arithmetic is defined for a structure of all CHARs (one byte long), assuming no padding.
In the case where manual editing of the code is possible (as opposed to the current situation involving a code generator), it might be possible to use the DEFINE preprocessor directive and replace the structure with an array as follows:
#define destValue tab[0]
#define srcValue tab[1]
However, in the given situation, the code is not MISRA compliant, since it violates the following compliance rules:
17.1 (required) : Pointer arithmetic shall only be applied to pointers that address an array or array element.
17.4 (required) : Array indexing shall be the only allowed form of pointer arithmetic.
Therefore, the only solution to this issue is to use the "-allow-ptr-arith-on-struct" option and treat the orange as safe.