mardi 22 août 2017

How to check _vfptr

Assuming the someClass has any member variables, doesn't really matter. If it helps you visualize in Visual Studio when you step through the code and hover over this someClass* A it has 4 member variables including a _vfptr.

Yes, I have googled what a _vfptr is and why it might be corrupted. I don't want to stop the reason it is corrupted, but instead check that it is corrupted and remove it from a list I have.

Is this possible, if so please let me know with the little snippet of code I have in the if(A_vfptr_is_not_corrupted) area, appreciate any insight!

Let's say I have the following:

function(someClass* A)
{
  //Yes I can have a null check like
  if(A) { //continue what I want to do }

  //If you hover over A it is not NULL, so it can continue the function
  //however, the _vfptr is 0x000000 {???, ???, etc. }
  //so later when I pass this pointer to another function and try to use it, it 
  //crashes the application.

  //Say I want to add it to some map or whatever, doesn't really concern what 
  //data structure i am storing to
  some_data_structure.insert(A);

  //But the real goal is to have something like:
  if(A_vfptr_is_not_corrupted) //A->_vfptr or something along the lines of that
   { 
     //then insert to some_data_structure.insert(A)
     //else just skip inserting
   }

C++/C++11/C++14 If this matters.

Aucun commentaire:

Enregistrer un commentaire