Problem while derefrance the void pointer?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
The polyspace 2016b code prover is showing Illegal derefrance pointer while derefrance the void pointer into an uint32 or float64 type.

0 commentaires
Réponses (1)
Gary
le 13 Avr 2017
Modifié(e) : Gary
le 13 Avr 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 commentaires
Voir également
Catégories
En savoir plus sur Command-Line Only Options dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!