MISRA C ++-2008规则5-0-15-数组索引应是指针算术的唯一形式 [英] MISRA C++-2008 Rule 5-0-15 - Array indexing shall be the only form of pointer arithmetic

查看:344
本文介绍了MISRA C ++-2008规则5-0-15-数组索引应是指针算术的唯一形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个在MISRA方面拥有更多经验的人来帮助我解决这个问题.我有以下代码:

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规则5-0-15也不允许使用ptr ++或ptr--.

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?

我的MISRA检查器是Coverity 7.0.3.3.

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.

这篇关于MISRA C ++-2008规则5-0-15-数组索引应是指针算术的唯一形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆