Thread: How to tackle a debug assertion failure?

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    17

    How to tackle a debug assertion failure?

    My application during run causes a debug assertion failed with an expression _BLOCK-TYPE_IS_VALID(pHead->nBlockUse) in the file dbgheap.c (line 1017).

    I understand that the problem is related to some kind of memory allocation and nothing much beyond this. I am writing and reading structs to/from files created in the program. The application reads from the created file but then gives the aforementioned error message.

    First in the class Change_setting (derived from CDialog) I have written a file by the name "Group". For writting the file I am using a structure type.

    Then in another class (of the same project)CLPDATADlg(again derived from CDialog) I try to read the file with the same structure. But after reading the file it gives the above error:

    Below is the code for writting and reading files.

    void Change_Setting::OnUpdateConfig()
    {
    struct Configuration
    {
    int portAdd;
    CString TimerClk;

    };
    struct Configuration Config1;
    CString str4;
    fstream file("GROUP", ios:ut|ios::in);
    if (!file){
    MessageBox("Cannot Open
    File","Error",MB_OK);
    }

    m_BaseAdd.GetWindowText(str4);
    char *end;
    Config1.portAdd = strtol(str4,&end,16);
    Config1.TimerClk = strin7;
    file.write((char*)&Config1,sizeof(Config1));
    file.close();
    }

    void CLPDATADlg::RUN()
    {
    struct Configuration1
    {
    int portAdd;
    CString TimerClk;

    };
    struct Configuration1 Config2;
    char str2[25],strin10[25];
    CString strg2,strg4,strg6,strg8;
    fstream in("GROUP", ios::in|ios::binary);
    if (!in){
    MessageBox("Cannot Open
    File","Error",MB_OK);
    return;
    }
    in.read((char*)&Config2,sizeof(Config2));
    portA = Config2.portAdd;
    in.close();
    }

    Please help me.....I am very badly stuck.

    Regards,

    Juhi
    Last edited by juhigarg; 11-12-2001 at 10:50 PM.

  2. #2
    Sorry don't know the anwser to your problem. But I also had some asertoin failures. but I lost them with changing my code. My question is: What are assertion failures?

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > in the file dbgheap.c (line 1017).
    This is going to be responsible for dynamic memory allocation (via new or malloc).

    Basically, between your previous call to new/malloc (which was successful), and this call (which wasn't), your code managed to corrupt the heap in some way - probably by overrunning the end of a previously allocated block.

    You need to check your use of any dynamic memory, to make sure you're not overrunning the ends.

    Other possibilities
    - using memory after you've done delete/free on it
    - using memory before you've called new/malloc
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File I/O Assertion Failure in VS2008
    By clegs in forum C Programming
    Replies: 5
    Last Post: 12-25-2008, 04:47 AM
  2. Debug Assertion failure problem
    By uldaman in forum C++ Programming
    Replies: 8
    Last Post: 01-21-2008, 02:22 AM
  3. debug assertion failure
    By talz13 in forum Windows Programming
    Replies: 2
    Last Post: 07-20-2004, 11:23 AM
  4. Debug Assertion Failure - bad pointer
    By ventolin in forum C++ Programming
    Replies: 5
    Last Post: 05-24-2004, 10:10 AM
  5. Debug Assertion Failure
    By gozlan in forum C Programming
    Replies: 2
    Last Post: 09-08-2002, 11:10 AM