Static Analyse Type Character

63 views Asked by At

My library have below function lines:

int
lwip_stricmp(const char* str1, const char* str2)
{
  char c1, c2;

  do {
    c1 = *str1++;
    c2 = *str2++;
...

I have MISRAC2012-Rule-10.3 error like this:

Implict conversion of '*str1++' from essential type unsigned 8-bit to different or narrover essential type character

Implict conversion of '*str2++' from essential type unsigned 8-bit to different or narrover essential type character

How can I solve this error or how can I suppress this error ?

1

There are 1 answers

2
Lundin On

If the code is as posted, then the tool is giving an incorrect diagnostic. No implicit promotions take place in the line c1 = *str1++; nor are there different essential types, both c1 and str are "essentially character type".

However, there is another (imo more serious) MISRA violation here. Combining ++ with other operators in the same expression is also strongly discouraged, particularly with other side effects, as in this case (see for example 13.3). Maybe this issue somehow fools your tool into producing the wrong diagnostic.

There's also rules about complex expressions and parenthesis etc. Make the code MISRA-C compliant like this:

c1 = *str1;
c2 = *str2;
str1++;
str2++;

If the tool is still complaining after the above fix, well then it's yet another bug in IAR's static analyser.