Problem with CString Variable

I am using a dialog class which is derived from another generic dialog class which itself is derived from CDialog

This class contains many CString varibles and it is working fine.

Later I added another CString variable.

Then also the corresponding dialog is properly opening(Modal Dialog), but after closing the dialog I am getting the following Assertion:

Run-Time Check Failure #2 - Stack around the 'dlg' was corrupted

When I click Retry it is taking me to the next statement from where the dialog is initiated using DoModal() method.

Here I found one strange behaviour.

If I put any char, int or float variable before this CString member variable I am not getting any error message.

But If I put double variable I am getting the same error message.

I tried to initialize that member variable in the constructor, in the OnInitDialog() method, then also I found the same behaviour.

Then I used static variable instead of member variable to make it work.

What could be the reason

Can anyone help on this.....



Answer this question

Problem with CString Variable

  • bhoopathi

    Memory leak and memory corruption are very different. I think it is more likely that the corruption problem still exists but is not being caught by run-time error checking. Perhaps you have fixed the problem but just do not realize it.

  • Carpet King

    The error message says that the stack is corrupted; another term (in this context) for stack is memory.

    As Einaros implies, somewhere in your program, memory is being modified that should not be. It could be occurring anywhere in the dialog but the C++ error-checking code does not detect the problem until the dialog ends. I think it is only coincidental that the problem occurs when you use a double but does not occur when you use other types of data. Since a double is larger than the other types, it might be that the memory corruption occurs in a manner that the error-checking code does not detect the problem when the shorter sizes of types are used. Use of static for the CString might also be hiding the problem until you modify the code again in a manner that allows the error-checking code to detect the problem.

    If my description is the explanation, then we might not be able to help without seeing all your code. I prefer to avoid looking at a large amount of code. There are tools for debugging memory corruption but I am not familiar with the details of how to use them.



  • michael447887

    I will check it again

    thanks


  • elittle27

    That error generally means that out of bounds writing has been done. Could you paste some of the source your application breaks at

  • Jeff Williams

    Let me ask a question,
    did u delete any resource (controls) from your dialog Any control variable still existing in DoDataExchange function for the invalid(deleted) controls


  • fatmanis

    Let me guess!
    Is your CDialog-derived class exported from a DLL



  • arkiboys



    It also can appears when using uninitialized variable. For example, the following code samples yield the same error message:
    void proc1_name()
    {
    int a;
    funct2(&a); // it crashes
    }

    int proc2_name()
    {
    int a;
    return a;// it crashes
    }

    // this sample demonstates array boundary exceeding
    void proc3_name()
    {
    int arr[2];
    arr[0] = 1;
    arr[1] = 2;
    arr[2] = 3; // on return you will get stack corruption
    }


    ___________________________________________________
    Best regards,
    Alexander Stoyan

    E-mail: alexander.stoyan@gmail.com
    MSN: alexander.stoyan@gmail.com
    ICQ: 295663150


  • Justin98TransAm

    I found the solution

    It is just because of one memory leak issue


  • Problem with CString Variable