Problem while derefrance the void pointer?
2 ビュー (過去 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!