Non-initialized variable
8 次查看(过去 30 天)
显示 更早的评论
Func_Process_ReadData ( uint8 OpStatus, uint8 *u8_DataOut, uint8 *u8_ErrorCode )
{
uint8 ErrorCode = INITIAL;
uint8 *ReadData = NULL;
Std_ReturnType ReturnCode = E_NOT_OK;
if(u8_DataOut != NULL)
{
ReadData = u8_DataOut;
ReturnCode = Call_DataServices_ReadData (ReadData);
}
ErrorCode = *u8_ErrorCode;
Status_Check (OpStatus);
Error_Check (ErrorCode);
return (ReturnCode);
}
Getting "Dereferenced value is read before being initialized." for this code snippet, even after adding the initializations. Can someone tell me, in case we are missing any steps? I'm getting this issue as an High Impact Defect on Polyspace BugFinder report.
回答(2 个)
Anirban
2021-5-24
编辑:Anirban
2021-5-24
Since the message refers to a 'dereferenced value', it is probably referring to the line:
ErrorCode = *u8_ErrorCode;
I don't see the buffer that u8_ErrorCode points to, in the code snippet itself. Maybe, u8_ErrorCode has not been made to point to a buffer before being passed to Func_Process_ReadData ?
PS Your workflow of using the HTML report to locate an issue seems quite tedious. Since you do have access to the code, I am wondering why you are not reviewing the results in the Polyspace desktop UI (or in a web browser with Polyspace Access). Anyway, if you contact Technical Support, they might provide you better solutions with the HTML report.
3 个评论
Anirban
2021-5-24
Your two code snippets together do not seem to lead to a Non-initialized variable defect. You might have to contact Technical Support and provide more context.
However, I am showing you a possibility of how one might get a Non-initialized variable defect with a slight variation of your code snippets. If you remove the bold parts, it is essentially the two code snippets you sent. This does not lead to a Non-initialized variable defect. But with the addition of the bold code, there now exists a path where the buffer pointed to by u8_ErrorCode might be non-initialized (basically it is the path that goes through the else branch). You might have something like this going on in your code.
Without a self-contained reproduction like this, it is difficult to diagnose what is going on.
#include <stdlib.h>
#define uint8 unsigned char
#define Std_ReturnType int
uint8 getRandom();
void func() {
/*--------------------------------------From another file-----------------------------------------------------*/
uint8 u8_DataOut[5] = {0,0,0,0,0};
uint8 ErrorCode;
uint8 pathDecider = getRandom();
if(pathDecider) {
ErrorCode = 0;
}
else
{} //On a path going through this, ErrorCode will be non-initialized.
uint8 OpStatus = 0;
Func_Process_ReadData ( OpStatus, u8_DataOut, &ErrorCode );
/*-----------------------------------------------------------------------------------------------------------------*/
}
Std_ReturnType Func_Process_ReadData ( uint8 OpStatus, uint8 *u8_DataOut, uint8 *u8_ErrorCode )
{
uint8 ErrorCode = 0;
uint8 *ReadData = NULL;
Std_ReturnType ReturnCode = 1;
if(u8_DataOut != NULL)
{
ReadData = u8_DataOut;
ReturnCode = Call_DataServices_ReadData (ReadData);
}
ErrorCode = *u8_ErrorCode;
Status_Check (OpStatus);
Error_Check (ErrorCode);
return (ReturnCode);
}
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Polyspace Products for Ada 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!