我的库有以下函数行:
int
lwip_stricmp(const char* str1, const char* str2)
{
char c1, c2;
do {
c1 = *str1++;
c2 = *str2++;
...我的MISRAC2012-Rule-10.3错误如下:
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如何解决此错误或如何抑制此错误?
发布于 2020-10-01 17:49:08
如果代码与发布的代码相同,则该工具给出的诊断不正确。在c1 = *str1++;行中没有发生隐式提升,也没有不同的基本类型,c1和str都是“本质上的字符类型”。
然而,这里还有另一个(imo更严重的) MISRA违规。也强烈不鼓励在同一表达式中将++与其他运算符组合,特别是在具有其他副作用的情况下(例如,参见示例13.3)。也许这个问题以某种方式欺骗了你的工具,使其产生了错误的诊断结果。
还有关于复杂表达式和括号等的规则。像这样使代码符合MISRA-C:
c1 = *str1;
c2 = *str2;
str1++;
str2++;如果该工具在上述修复后仍在抱怨,那么这是IAR的静态分析器中的另一个bug。
https://stackoverflow.com/questions/64152244
复制相似问题