Problem while derefrance the void pointer?
조회 수: 5 (최근 30일)
이전 댓글 표시
The polyspace 2016b code prover is showing Illegal derefrance pointer while derefrance the void pointer into an uint32 or float64 type.

댓글 수: 0
답변 (1개)
Gary
2017년 4월 13일
편집: Gary
2017년 4월 13일
It's difficult to understand your case exactly, because there's no reproduction example.
If your case is similar with below example code, you have to be careful when you do casting.
const int gintvar = 100;
const float gfltvar = 100.0;
void test (void)
{
volatile int cond = 0;
const void * vPtr;
double temp;
if (cond)
{
vPtr = &gintvar;
}
else
{
vPtr = &gfltvar;
}
temp = *(double const *) vPtr;
}
On the 32-bit target, this code occurs "Illegally Dereferenced Pointer" because vPtr points 4 bytes variables such as gintvar and gfltvar, but it casts to read 8 bytes, double from the pointer.
Similar case can be occurred with unsigned integer. Please look below example code.
const char gchvar = 100;
const short gshtvar = 100;
void test (void)
{
volatile int cond = 0;
const void * vPtr;
unsigned int temp;
if (cond)
{
vPtr = &gchvar;
}
else
{
vPtr = &gshtvar;
}
temp = *(unsigned int const *) vPtr;
}
In the above example, vPtr points to 1 byte or 2 bytes variables such as gchvar and gshtvar, but it accesses by unsigned int (4 bytes), it causes "Illegally Dereferenced Pointer".
I hope this is helpful for you to understand the issue.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Command-Line Only Options에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!