When this happens in a DLL you might get something like External Exception 0x80000003
In C/C++ when a variable is defined in a function, it will go on the stack. When you use new, it will go on the heap. Now consider the following:
buffer = "!"; //event buffer is already out of range!
This means you will write over the boundaries of your character array (a string). When you leave this function, you leave the function-scope and the stack around this buffer is corrupted. When you have this kind of error, you should check the variable for writing behind its boundaries. Most of the time you can correct these problems with adding 1 to your array. (This is due to the syntax of C/C++ which makes it difficult to exactly stay in your boundaries)
Please note the following:
char buffer; //this can only contain 1 character! NOT 2!
This means in fact that buffer is already out of range!
The following function will deliver the error:
strcp(buffer, "This is longer than 10 and so will corrupt your stack");
Here I added a whole application and documented where it goes wrong! It is a Qt console application.
buffer = 'a';
buffer = 'b'; //here it goes wrong! This is out of the boundaries!
int main(int argc, char *argv)
using namespace std;
QCoreApplication a(argc, argv);
cout << "Buffertest starts..." << endl;
cout << "Buffertest ended." << endl;
QTimer::singleShot(500, &a, SLOT(quit())); //otherwise the program will not end!
Disclaimer:The information provided in this document is intended for your information only. Lubby makes no claims to the validity of this information. Use of this information is at own risk!
About the Author
Author:- Keskon GmbH & Co. KG
Wim Peeters is electronics engineer with an additional master in IT and over 30 years of experience, including time spent in support, development, consulting, training and database administration. Wim has worked with SQL Server since version 6.5. He has developed in C/C++, Java and C# on Windows and Linux. He writes knowledge base articles to solve IT problems and publishes them on the Lubby Knowledge Platform.