Assertion Failure I give up.

This is a discussion on Assertion Failure I give up. within the Windows Programming forums, part of the Platform Specific Boards category; On Debug Mode. After I make a call to Save Dialog and save the information from the edit boxes and ...

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Assertion Failure I give up.

    On Debug Mode. After I make a call to Save Dialog and save the information from the edit boxes and then close the window I get an assertion error.
    Attached Files Attached Files
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    I can assure you that to the best of my knowledge there's no virus, check for viruses first though.
    Attached Files Attached Files
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    Code:
    //we incremente iCount to accomodate for the NULL character
    //OK, so why don't you increment it then, having said you would?
    NameOfFile=new char [iCount];
    
    // now you lie about the size of the allocated memory
    GetWindowText(NameEditBoxHwnd,NameOfFile,iCount+1);
    
    // what is the point of this?
    // you allocate it here, you pass it to another function below
    // then you free it
    FileToSave= new char [iCount+1];
    
    OpenFileName.hwndOwner         = NULL;
    OpenFileName.lpstrFile         = NameOfFile;
    OpenFileName.lpstrFileTitle	   =FileToSave;

    > I get an assertion error.
    In the memory manager no doubt, judging from the number of places where you try and put n+1 bytes into an n-byte buffer.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Thanks I'll look into it.....I see that I increment icount after a call to GetWindowsText

    GetWindowText(NameEditBoxHwnd,NameOfFile,iCount+1) ;
    FileToSave= new char [iCount+1];


    The problem might lie there............thanks



    PS. I really didn't know computers were so picky about pointers in memory.
    Last edited by incognito; 01-04-2004 at 05:30 AM.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  5. #5
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    I think I found the problem...

    Code:
    	NameEditBoxHwnd=GetDlgItem(DialogHandle, IDC_NOMBRE);
    	iCount=GetWindowTextLength(NameEditBoxHwnd);
    	//we incremente iCount to accomodate for the NULL character
    	NameOfFile=new char [iCount];

    I am only allocating enough space on NameOfFile to fit the Name of the Client, but when GetSaveFileName (&OpenFileName) returns after I filled part of the structure like so.

    OpenFileName.lpstrFile =NameOfFile;

    After the function returns NameOFile will contain.......

    "Pointer to a buffer that contains a filename used to initialize the File Name edit control. The first character of this buffer must be NULL if initialization is not necessary. When the GetOpenFileName or GetSaveFileName function returns successfully, this buffer contains the drive designator, path, filename, and extension of the selected file. "

    So basically I just needed a bigger buffer. Thank you.


    So now I changed.......



    NameOfFile=new char [iCount];

    to

    NameOfFile=new char[150];

    Thus allocating a bigger buffer

    Last edited by incognito; 01-04-2004 at 11:27 AM.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  6. #6
    Registered User
    Join Date
    Oct 2003
    Posts
    13
    Originally posted by incognito

    So now I changed.......



    NameOfFile=new char [iCount];

    to

    NameOfFile=new char[150];

    Thus allocating a bigger buffer

    Perhaps it would be better or at least safer to use
    Code:
    NameOfFile=new char [MAX_PATH];
    instead because MAX_PATH defines the maximum chars a path can have (260). it's defined in windef.h

  7. #7
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Yeah very true.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    > NameOfFile=new char [MAX_PATH];
    There's not a lot of point using new to allocate space with a known length at compile time.

    char NameOfFile[MAX_PATH];
    makes life so much simpler.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Also very true....I wasn't thinking about the extra things that were going to be added to the buffer when I was coding it, that's why I put it like that, you're right I will change it.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someone give me an example of the following
    By Overworked_PhD in forum C Programming
    Replies: 11
    Last Post: 05-31-2009, 09:37 AM
  2. File I/O Assertion Failure in VS2008
    By clegs in forum C Programming
    Replies: 5
    Last Post: 12-25-2008, 03:47 AM
  3. How to tackle a debug assertion failure?
    By juhigarg in forum C++ Programming
    Replies: 2
    Last Post: 11-12-2001, 11:59 AM
  4. How To Give A Font Colour ?
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 09-14-2001, 01:22 PM
  5. "delete []" in destructor causes assertion failure
    By TerranFury in forum C++ Programming
    Replies: 3
    Last Post: 08-27-2001, 11:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21