Problem while derefrance the void pointer?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
The polyspace 2016b code prover is showing Illegal derefrance pointer while derefrance the void pointer into an uint32 or float64 type.

0 Kommentare
Antworten (1)
Gary
am 13 Apr. 2017
Bearbeitet: Gary
am 13 Apr. 2017
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 Kommentare
Siehe auch
Kategorien
Mehr zu Command-Line Only Options finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!