MATLAB Answers

Non-initialized variable

6 views (last 30 days)
Sam
Sam on 23 May 2021
Commented: Sam on 24 May 2021
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 Comments
Sam
Sam on 24 May 2021
Not really sure. Since using CUI, we are only having the HTML report with us.

Sign in to comment.

Answers (2)

Sam
Sam on 24 May 2021
Not really sure. Since using CUI, we are only having the HTML report with us.

Anirban
Anirban on 24 May 2021
Edited: Anirban on 24 May 2021
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 Comments
Sam
Sam on 24 May 2021
Thanks for the reply.
The code I have shared, is the flow that is there. We don't have any branching in that code snippet.
That's why wondering, if everything's correct, where are we going wrong. And hence, had to post here for a better understanding.
I'll again check the same, and try to re-consider the flow, if we can get something out of it.

Sign in to comment.

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by