这个任务是多余的。在修改之前,从未使用此对象的值| MISRA_2012 QAC,消息标识符2982
我要低于Misra Qac警告。
这个任务是多余的。修改之前,从未使用此对象的值。 MISRA_2012,QAC,消息标识符:2982
我试图修改变量的本地状态为特定的错误值。
代码:
FUNC(void, RTE_CODE) Rte_Server_S_service_exteriorLighting_UI_unsubscribeExteriorLightSettings (ExteriorLightingUI_unsubscribeExteriorLightSettings_subscriptionId_type subscriptionId, P2CONST(uint8, AUTOMATIC, RTE_APPL_DATA) consumerId, P2VAR(ExteriorLightingUI_AT_SubscriptionStatus, AUTOMATIC, RTE_APPL_DATA) status)
{
uint16 localStatus;
TS_MemSet(&localStatus, 0u, sizeof(localStatus));
uint8 conId;
uint8 isSubIdFound = COMH_FALSE;
if(subscriptionId == COMH_SUBSCRIPTION_TO_ALL)
{
conId = SubAll_ES_is_validate_ConsumerId(consumerId); //function call
if(conId < 2u)
{
localStatus = (uint16) COMH_SOMEIP_SUBSCRIPTION_CANCELLED;
isSubIdFound = COMH_TRUE;
}
else
{
localStatus = (uint16) COMH_SOMEIP_SUBSCRIPTION_ERROR;
}
}
else
{
localStatus = (uint16) COMH_SOMEIP_SUBSCRIPTION_ERROR;
}
if(isSubIdFound == COMH_FALSE)
{
localStatus = (uint16) COMH_SOMEIP_SUBSCRIPTION_TARGET_DELETED;
}
/* fill response buffer of SOMEIP method */
TS_MemCpy(status, &localStatus, sizeof(localStatus));
}
在此语句之前,我使用memset填写0个值 localstatus。
在此陈述之后,我使用memcpy来填补受尊敬的 LocalStatus中的错误代码。
I am getting below MISRA QAC Warning.
This assignment is redundant. The value of this object is never used before being modified.
MISRA_2012, QAC, Message Identifier: 2982
I am trying to modify local status of variable to specific error value.
code:
FUNC(void, RTE_CODE) Rte_Server_S_service_exteriorLighting_UI_unsubscribeExteriorLightSettings (ExteriorLightingUI_unsubscribeExteriorLightSettings_subscriptionId_type subscriptionId, P2CONST(uint8, AUTOMATIC, RTE_APPL_DATA) consumerId, P2VAR(ExteriorLightingUI_AT_SubscriptionStatus, AUTOMATIC, RTE_APPL_DATA) status)
{
uint16 localStatus;
TS_MemSet(&localStatus, 0u, sizeof(localStatus));
uint8 conId;
uint8 isSubIdFound = COMH_FALSE;
if(subscriptionId == COMH_SUBSCRIPTION_TO_ALL)
{
conId = SubAll_ES_is_validate_ConsumerId(consumerId); //function call
if(conId < 2u)
{
localStatus = (uint16) COMH_SOMEIP_SUBSCRIPTION_CANCELLED;
isSubIdFound = COMH_TRUE;
}
else
{
localStatus = (uint16) COMH_SOMEIP_SUBSCRIPTION_ERROR;
}
}
else
{
localStatus = (uint16) COMH_SOMEIP_SUBSCRIPTION_ERROR;
}
if(isSubIdFound == COMH_FALSE)
{
localStatus = (uint16) COMH_SOMEIP_SUBSCRIPTION_TARGET_DELETED;
}
/* fill response buffer of SOMEIP method */
TS_MemCpy(status, &localStatus, sizeof(localStatus));
}
Before this statement I am using memset to fill 0 value in
localStatus.
After this statement, I am using memcpy to fill respected
error code in localStatus.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
原因很可能是
ts_memcpy(status status,status&amp; localstatus,sizeof(localstatus));
,应为&amp; status
。如果是这样,这不仅应该是违反Misra的行为,还应是C编译器错误。也可能还有其他原因:静态分析仪可能无法解决这些各种功能,因为您通过文件运行该功能,而不是一次在整个项目中运行。然后,静态分析仪在将非初始化变量传递给函数时倾向于发牢骚,但这在大多数情况下都是假积极的。
或者,如果静态分析仪真的很聪明,则告诉您这些功能调用只是胡说八道,这可能是正确的。我不知道这些功能是什么,但是代码确实看起来很腥。您可能有一些有效的拨打它们的理由(原子访问?符合MISRA的STD lib?),但通常对于普通
uint16_t
,您应该简单地做:Very likely the cause is
TS_MemCpy(status, &localStatus, sizeof(localStatus));
which should be&status
. If so, this should not just be a MISRA violation but a C compiler error.There might also be other reasons: the static analyser might not be able to resolve these various functions since you run it file by file and not at the whole project at once. Static analysers then tend to whine when passing uninitialized variables to functions, but that's a false positive most of the time.
Or if the static analyser is really smart, it is telling you that these function calls are just nonsense, which might be true. I don't know what these functions do but the code does looks fishy. You might have some valid reasons for calling them (atomic access? MISRA compliant std lib?), but generally for a plain
uint16_t
you should simply do:不确定我是否在代码中遇到了问题,但是如果您替换
comh_someip_subscription_error
tolocalstatus
comh_someip_someip_someip_subscription_target_deleted ,您可以删除周围的所有内容IssubidFound
。您可以做到这一点,因为对
localstatus
的最后一个分配是多余的。因此,我想说您的Misra Checker是对的。
Not sure whether I get something wrong in the code, but if you replace the assignments of
COMH_SOMEIP_SUBSCRIPTION_ERROR
tolocalStatus
withCOMH_SOMEIP_SUBSCRIPTION_TARGET_DELETED
, you can remove everything aroundisSubIdFound
.And you can do this, because the last assignment to
localStatus
is redundant.So I would say your MISRA checker is right.