C++ Unhandled exception at 0x00000000

Discussion in 'C++' started by AMT2K5, Nov 27, 2005.

  1. AMT2K5

    AMT2K5 Guest

    Hello, I am trying to figure out the source of this unhandled exception
    (bad pointer or unallocated memory)

    I have a parent class, IOField with the following pointer to function

    bool (*isValid)(void *data, IOScreen *scrPtr);

    This holds the address of a function that is desinged to validate the
    data of an IOField after being edited. The IOField is displayed in an
    IOSCreen pointed by "scrPtr".

    Now later on in a child class, I want to make a function call to
    isValid;

    if(isValid(data,this->owner) == false) condition = true;

    Previous functions allocate memory for data and store strings in them,
    and this->owner is set in the constructor.

    data and, this->owner has an address but isValid does not.

    When compiling, the only address with 0x00000000 is isValid;

    Visual Studio 2005 reports,
    data 0x00129ac8 void *
    + owner 0x0012920c {fnum=15 row=2 col=5 ...}
    IOScreen *
    isValid 0x00000000 bool (void *, IOScreen *)*
    + this 0x00356b48 {flen=20 slen=40 curpos=0 ...}
    IOLineEdit * const

    Maybe I am doing something wrong with pointer to functions, I dont have
    *that* much experience using them (they are required in this college
    assignment).

    Appreciate any help and thanks in advance.
     
    AMT2K5, Nov 27, 2005
    #1
    1. Advertising

  2. AMT2K5

    Artie Gold Guest

    AMT2K5 wrote:
    > Hello, I am trying to figure out the source of this unhandled exception
    > (bad pointer or unallocated memory)
    >
    > I have a parent class, IOField with the following pointer to function
    >
    > bool (*isValid)(void *data, IOScreen *scrPtr);
    >
    > This holds the address of a function that is desinged to validate the
    > data of an IOField after being edited. The IOField is displayed in an
    > IOSCreen pointed by "scrPtr".
    >
    > Now later on in a child class, I want to make a function call to
    > isValid;
    >
    > if(isValid(data,this->owner) == false) condition = true;
    >
    > Previous functions allocate memory for data and store strings in them,
    > and this->owner is set in the constructor.
    >
    > data and, this->owner has an address but isValid does not.
    >
    > When compiling, the only address with 0x00000000 is isValid;
    >
    > Visual Studio 2005 reports,
    > data 0x00129ac8 void *
    > + owner 0x0012920c {fnum=15 row=2 col=5 ...}
    > IOScreen *
    > isValid 0x00000000 bool (void *, IOScreen *)*
    > + this 0x00356b48 {flen=20 slen=40 curpos=0 ...}
    > IOLineEdit * const
    >
    > Maybe I am doing something wrong with pointer to functions, I dont have
    > *that* much experience using them (they are required in this college
    > assignment).
    >
    > Appreciate any help and thanks in advance.
    >

    Have you initialized/assigned a value to `isValid'? (It sure looks like
    you haven't.)

    Show us the constructors for your class and we might be able to help.

    HTH,
    --ag

    --
    Artie Gold -- Austin, Texas
    http://goldsays.blogspot.com (new post 8/5)
    http://www.cafepress.com/goldsays
    "If you have nothing to hide, you're not trying!"
     
    Artie Gold, Nov 27, 2005
    #2
    1. Advertising

  3. AMT2K5

    AMT2K5 Guest

    IOField::IOField(int row, int col,void (*help)(IOScreen *), bool
    (*isValid)(void *, IOScreen *)):Ok(true){
    this->row = row;
    this->col = col;
    this->help = help;
    this->isValid = isValid;
    this->data = NULL;
    setOwner(NULL);
    }



    IOLineEdit::IOLineEdit(int row, int col, int flen, int slen, int *ins,
    void (*help)(IOScreen *), bool (*isValid)(void *, IOScreen *)
    ):IOField(row,col,help,isValid){
    Ok = false;
    data = new char[slen+1];
    if(data){
    Ok = true;
    dynamic = true;
    curpos = spos = 0;
    this->flen = flen;
    this->slen = slen;
    this->ins = ins;
    ((char*)data)[0] = 0;
    }
    }
     
    AMT2K5, Nov 27, 2005
    #3
  4. AMT2K5 wrote:
    > Hello, I am trying to figure out the source of this unhandled exception
    > (bad pointer or unallocated memory)
    >
    > I have a parent class, IOField with the following pointer to function
    >
    > bool (*isValid)(void *data, IOScreen *scrPtr);
    >
    > This holds the address of a function that is desinged to validate the
    > data of an IOField after being edited. The IOField is displayed in an
    > IOSCreen pointed by "scrPtr".
    >
    > Now later on in a child class, I want to make a function call to
    > isValid;
    >
    > if(isValid(data,this->owner) == false) condition = true;
    >
    > Previous functions allocate memory for data and store strings in them,
    > and this->owner is set in the constructor.
    >
    > data and, this->owner has an address but isValid does not.
    >
    > When compiling, the only address with 0x00000000 is isValid;
    >
    > Visual Studio 2005 reports,
    > data 0x00129ac8 void *
    > + owner 0x0012920c {fnum=15 row=2 col=5 ...}
    > IOScreen *
    > isValid 0x00000000 bool (void *, IOScreen *)*
    > + this 0x00356b48 {flen=20 slen=40 curpos=0 ...}
    > IOLineEdit * const
    >
    > Maybe I am doing something wrong with pointer to functions, I dont have
    > *that* much experience using them (they are required in this college
    > assignment).
    >
    > Appreciate any help and thanks in advance.
    >


    Well nowhere in this descrption have you said where you assign an
    address to isValid. Also judging by your debugger output isValid has an
    address of NULL. Is it possible you just forgot to assign an address to
    isValid?

    If this doesn't help then remove all extraneous code from your program,
    so that you have a small but still compilable program which still has
    this problem, then post the entire code here. It's difficult to solve
    coding problems without seeing the code.

    john
     
    John Harrison, Nov 27, 2005
    #4
  5. AMT2K5 wrote:
    > IOField::IOField(int row, int col,void (*help)(IOScreen *), bool
    > (*isValid)(void *, IOScreen *)):Ok(true){
    > this->row = row;
    > this->col = col;
    > this->help = help;
    > this->isValid = isValid;
    > this->data = NULL;
    > setOwner(NULL);
    > }
    >
    >
    >
    > IOLineEdit::IOLineEdit(int row, int col, int flen, int slen, int *ins,
    > void (*help)(IOScreen *), bool (*isValid)(void *, IOScreen *)
    > ):IOField(row,col,help,isValid){
    > Ok = false;
    > data = new char[slen+1];
    > if(data){
    > Ok = true;
    > dynamic = true;
    > curpos = spos = 0;
    > this->flen = flen;
    > this->slen = slen;
    > this->ins = ins;
    > ((char*)data)[0] = 0;
    > }
    > }
    >


    Well there is nothing wrong with that code. But somewhere in your
    program you have a bug. This could take a while.

    Please have a look at the guidelines for posting code

    http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.8

    Follow those recommendations and you'll have a solution very quickly

    john
     
    John Harrison, Nov 27, 2005
    #5
  6. AMT2K5

    AMT2K5 Guest

    I see how isValid is NULL which I dont understand since I set it in the
    parent constructor

    this->isValid = isValid
     
    AMT2K5, Nov 27, 2005
    #6
  7. AMT2K5

    Jim Langston Guest

    "AMT2K5" <> wrote in message
    news:...
    >I see how isValid is NULL which I dont understand since I set it in the
    > parent constructor
    >
    > this->isValid = isValid
    >


    Yes, but you are assuming that the isValid passed in isn't null.

    Put a debug break on that line.

    Then debug the program. What is the value of the isValid you are passing
    in? I'll bet you it's null.
     
    Jim Langston, Nov 27, 2005
    #7
  8. AMT2K5

    AMT2K5 Guest

    Correct, yes it is.
     
    AMT2K5, Nov 27, 2005
    #8
  9. AMT2K5

    Jim Langston Guest

    "AMT2K5" <> wrote in message
    news:...
    > Correct, yes it is.
    >


    Well, so now you know your problem, right? You're passing null in. Find
    out where you're passing it in, and find out why you're passing null.
     
    Jim Langston, Nov 27, 2005
    #9
  10. AMT2K5

    AMT2K5 Guest

    Trying to understand what you said, I think the problem lies within the
    = NULL defaults im using in the class definition?

    public:
    IOLineEdit( char *str, int row, int col, int flen, int slen,
    int *ins = NULL, void (*help)(IOScreen *) = NULL,
    bool (*isValid)(void *, IOScreen *) = NULL);
    IOLineEdit(int row, int col, int flen, int slen, int *ins = NULL,
    void (*help)(IOScreen *) = NULL,
    bool (*isValid)(void *, IOScreen *) = NULL);
     
    AMT2K5, Nov 27, 2005
    #10
  11. AMT2K5

    Jim Langston Guest

    "AMT2K5" <> wrote in message
    news:...
    > Trying to understand what you said, I think the problem lies within the
    > = NULL defaults im using in the class definition?
    >
    > public:
    > IOLineEdit( char *str, int row, int col, int flen, int slen,
    > int *ins = NULL, void (*help)(IOScreen *) = NULL,
    > bool (*isValid)(void *, IOScreen *) = NULL);
    > IOLineEdit(int row, int col, int flen, int slen, int *ins = NULL,
    > void (*help)(IOScreen *) = NULL,
    > bool (*isValid)(void *, IOScreen *) = NULL);


    What that means is, "if I don't pass any parameter in this slot, make the
    parater this value." So if you don't pass a parameter in the slot for
    isValid, it will assign isValid the value of NULL.

    So, where are you calling IOLineEdit? It might be a constructor (proably
    is) so how you are instatizing IOLineEdit?

    Like, IOLineEdit MyVar(10, 20, 30, 40); or? Look at the line where you are
    instatizing the IOLineEdit object. Look at the parameters you are passing
    in. Are you passing a parameter in for the isValid parm? (8th parm for
    your first constructor, 7th parm for you're 2nd constructor).
     
    Jim Langston, Nov 27, 2005
    #11
  12. AMT2K5

    Mike Smith Guest

    AMT2K5 wrote:
    > I see how isValid is NULL which I dont understand since I set it in the
    > parent constructor
    >
    > this->isValid = isValid


    And what is the "isValid" on the RHS? Where does its value come from?

    --
    Mike Smith
     
    Mike Smith, Nov 29, 2005
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ola
    Replies:
    0
    Views:
    561
  2. Tedka
    Replies:
    2
    Views:
    2,715
    Mr. Dot Net
    Jul 19, 2004
  3. Askari
    Replies:
    4
    Views:
    7,101
    Alex Martelli
    Sep 1, 2004
  4. Warren Tang
    Replies:
    1
    Views:
    919
    Warren Tang
    Sep 23, 2008
  5. Sparky
    Replies:
    3
    Views:
    2,617
    Sparky
    Aug 4, 2009
Loading...

Share This Page