Problem while derefrance the void pointer?
1 次查看(过去 30 天)
显示 更早的评论
The polyspace 2016b code prover is showing Illegal derefrance pointer while derefrance the void pointer into an uint32 or float64 type.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/161682/image.png)
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 中查找有关 Bug Finder Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!